https://codeforces.com/contest/1095/problem/C

题解:贪心

一直往大了塞就行了

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=200000+1000;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
ll a[64];
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endifa[0]=1;for(int i=1;i<40;i++){a[i]=a[i-1]*2;}scanf("%d%d",&n,&k);t=n;if(n==0&&k==0){cout << "YES" << endl;return 0;}if(n<k){cout << "NO" << endl;return 0;}stack<ll>st;int sum=0;for(int i=32;i>=0;i--){while(a[i]<=n&&k-1<=n-a[i]&&n&&k){//保证在这个数减掉以后接下来的k-1个数至少为1st.push(a[i]);sum+=a[i];k--;n-=a[i];}}if(sum!=t){cout << "NO" << endl;return 0;}cout << "YES" << endl;while(!st.empty()){cout <<st.top() << " ";st.pop();}//cout << "Hello world!" << endl;return 0;
}

Powers Of Two相关推荐

  1. UVA 10515 - Powers Et Al.(数论)

    UVA 10515 - Powers Et Al. 题目链接 题意:求出m^n最后一位数 思路:因为m和n都非常大,直接算肯定是不行的,非常easy想到取最后一位来算,然后又非常easy想到最后一位不 ...

  2. Codeforces 955C Sad powers(数论)

    Codeforces 955C Sad powers 题意 q组询问,每次询问给定L,R,求[L,R]区间内有多少个数可以写成ap的形式,其中a>0,p>1,1 ≤ L ≤ R ≤ 1e1 ...

  3. MATLAB报错“Integers can only be raised to positive integral powers.“

    报错代码是下面这样的: I=imread('pout.jpg'); if size(I,3)>1  %判断如果是彩色图像,转换为灰度图     I=rgb2gray(I); end Gamma_ ...

  4. Relatively Prime Powers CodeForces - 1036F (莫比乌斯函数容斥)

    Relatively Prime Powers CodeForces - 1036F Consider some positive integer xx. Its prime factorizatio ...

  5. April Fools Day Contest 2016 A. Da Vinci Powers

    A. Da Vinci Powers 题目连接: http://www.codeforces.com/contest/656/problem/A Description The input conta ...

  6. UVA11752 The Super Powers【超级幂+暴力+数论】

    We all know the Super Powers of this world and how they manage to get advantages in political warfar ...

  7. Project Euler Problem 48: Self powers

    Self powers Problem 48 The series, 11 + 22 + 33 + ... + 1010 = 10405071317. Find the last ten digits ...

  8. Educational Codeforces Round 50: F. Relatively Prime Powers(莫比乌斯函数)

    F. Relatively Prime Powers 题意: 给你一个n,问满足在[2,n]范围内有多少个数是非次方数(也就是不是这样的) 思路: 答案就是 原理是利用容斥,注意n开i次根是向下取整( ...

  9. 英国内政部(Home Office)间谍机构(spy powers)假装它是Ofcom咨询中的一名私人公民1514378282474...

    . 这是博客内容,我很好,我很开心. 独家英国内政部的调查权力机构(提升机)匿名回应了一项Ofcom的协商,敦促监管机构对GSM设备进行"安全"相关的禁令,以帮助人们在国外得到便宜 ...

  10. 英国内政部(Home Office)间谍机构(spy powers)假装它是Ofcom咨询中的一名私人公民1514378369635...

    . 这是博客内容,我很好,我很开心. 独家英国内政部的调查权力机构(提升机)匿名回应了一项Ofcom的协商,敦促监管机构对GSM设备进行"安全"相关的禁令,以帮助人们在国外得到便宜 ...

最新文章

  1. springcloud项目打包_SpringCloud 快速入门
  2. python中日期和时间格式化输出的方法小结_Python 时间操作例子和时间格式化参数小结...
  3. 我眼中未来的计算机作文600字,我的电脑作文600字
  4. Vysor_v1.6.9
  5. ASA IPSEC ×××配置
  6. 区块链不适用的若干场景
  7. python学习之路-1 python简介及安装方法
  8. 【LeetCode】48. Rotate Image (2 solutions)
  9. SSH pts 虚拟终端
  10. PHP-FPM,Nginx,FastCGI 之间的关系
  11. php 二维数组 根据值 找,PHP编程根据二维数组某个字段的值查找值所在的一维数组...
  12. 【训练平台】mmdetection训练自己的标注数据, 以faster RCNN ,yolo为例子
  13. php gd libpng,libpng版本问题导致的PHP调用gd扩展出错解决方案
  14. MindManager 2021授权许可密钥思维导图软件
  15. Linux复制文件到当前目录
  16. docx文档文字怎么加边框_word给正文加边框 word怎样给一段文字加上边框
  17. win7计算机进行重镜像,win7镜像重装系统图文教程
  18. PLSQL登录时怎么输入数据库地址
  19. iOS APP调取短信 发送消息给其他人
  20. 研究开源项目发现的一个人性化的Go语言库

热门文章

  1. java数据结构队列杨辉三角_使用队列实现杨辉三角
  2. c语言中怎么转换类型数据类型,C语言中数据类型转换
  3. 【线性控制理论】状态观测器—开环形式的状态观测器
  4. android EditText 自动换行 设置
  5. gensim 快速入门 Word2Vec
  6. [RK3288][Android6.0] 设置中通过Sensor旋转显示画面小结
  7. 各类Excel表格批量合并问题的实现思路与案例
  8. 大数据开发好还是大数据分析好?哪个薪资高?
  9. GNSS北斗GPS教学实验箱
  10. Kidult打卡第三弹