Duff and Weight Lifting - 587A
题目大意:某个人训练举重,他每次可以举起来2^wi的重量,不过这个人比较懒所以他想尽量减少训练的次数,如果所有的训练重量2^a1 +2^a2+....2^ak = 2^x,那么这些重量可以一次性训练(不需要连续),问他最少要训练几次才行。
分析:
已知 2^x+2^x = 2^(x+1),所以相同的是可以合并成下一个的,最后只需要判断,有多少个不能合成的即可。
代码如下:
- #include<iostream>
- #include<string.h>
- #include<stdio.h>
- #include<algorithm>
- #include<math.h>
- #include<queue>
- using namespace std;
- const int MAXN = 2e6+;
- int a[MAXN+];
- int main()
- {
- int N, x, ans=;
- scanf("%d", &N);
- for(int i=; i<N; i++)
- {
- scanf("%d", &x);
- a[x] += ;
- }
- for(int i=; i<MAXN; i++)
- {
- a[i+] += a[i] / ;
- a[i] %= ;
- ans += a[i];
- }
- printf("%d\n", ans);
- return ;
- }
Duff and Weight Lifting - 587A的更多相关文章
- Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting
B. Pasha and PhonePasha has recently bought a new phone jPager and started adding his friends' phone ...
- Codeforces Round #326 (Div. 2) C. Duff and Weight Lifting 水题
C. Duff and Weight Lifting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- codeforces587a//Duff and Weight Lifting// Codeforces Round #326 (Div. 1)
题意:一数列an,如果存在一个k,有2^(ai)+2^(aj)+......=2^k成立,那么一次能拿走ai,aj这些全部.问最少拿的次数. 太简单. 乱码 //#pragma comment(lin ...
- 【Henu ACM Round#14 C】Duff and Weight Lifting
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 2^y可以由两个2^(y-1)相加得到. 则有一个贪心的策略. 就是2^x尽量都变成2^(x+1) (即能够凑就尽量凑) 如果x还有 ...
- BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)
Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- hdu 5610 Baby Ming and Weight lifting
Problem Description Baby Ming is fond of weight lifting. He has a barbell pole(the weight of which c ...
- cf Round 587
A.Duff and Weight Lifting(思维) 显然题目中只有一种情况可以合并 2^a+2^a=2^(a+1).我们把给出的mi排序一下,模拟合并操作即可. # include <c ...
- 2021record
2021-10-14 P2577 [ZJOI2004]午餐 2021-10-13 CF815C Karen and Supermarket(小小紫题,可笑可笑) P6748 『MdOI R3』Fall ...
- PHP实现文字写入图片功能
/** * PHP实现文字写入图片 */class wordsOnImg { public $config = null; /** * @param $config 传入参数 * @param $co ...
随机推荐
- Hbase region 某个regionserver挂掉后的处理
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAwoAAACdCAMAAAAjbX91AAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK
- CSS3画三角形原理
1.首先看一下画出一个下三角形完整的代码及效果图 #trangle1-up{ width:; height:; border-left:50px solid transparent; border-r ...
- django的url的name参数的意义(转发)
http://bio.rusaer.com/archives/288 Django一个比较隐含的函数url 阅读量(5010) | 发表 于 2010-03-09 14:26:18 Djang ...
- Asp.net MVC 视图之公用代码
一.公共模板 转自:http://www.cnblogs.com/kissdodog/archive/2013/01/07/2848881.html 1.@RenderBody() 在网站公用部分通过 ...
- DJANGO:从当前用户的所属用户组里查找其所拥有的权限矩阵
没办法,随时项目越来越精进,要求也越来越多. 以前的权限精度已满足不了现在的要求, 那就设计一个权限矩阵,用HOOK返回来判断吧... [莫名其妙的ORM,留个念想] 主要是在表之间的跳转,要注意语法 ...
- IndexReader和IndexWriter的生命周期
http://youyang-java.iteye.com/blog/1731205 对于IndexReader而言,反复使用 IndexReader .open打开会有很大的开销,所以一般在整个程序 ...
- java客户端连接MongoDB数据库的简单使用
1.下载mongoDB的jar包,并引入到工程的CLASSPATH中下载:mongodb2.5驱动包下载 如果使用maven项目,最新的依赖如下: <dependency> <gro ...
- vcastr2.0插件超级简单使用
Vcastr2.0简单使用 友情提示:1.蓝色文字为必修改内容.2.#字符后面是解释该代码段的主要内容 1. 引用swfobject.js文件 #public/videoplu ...
- 气死人不偿命,Q_OBJECT导致的C++报错,而且还看不明白(#ifdef没控制好,导致什么都不认识了)
为了代码可以同时适应VC++和MingW编译器,我改动了我的代码,变成: #ifdef _MSC_VER #pragma comment(lib, "crypt32.lib") / ...
- 【HDOJ】1540 Tunnel Warfare
还不错的一道线段树区间合并.挺巧妙的用法. /* 1540 */ #include <iostream> #include <string> #include <map& ...