题目大意:某个人训练举重,他每次可以举起来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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. codeforces587a//Duff and Weight Lifting// Codeforces Round #326 (Div. 1)

    题意:一数列an,如果存在一个k,有2^(ai)+2^(aj)+......=2^k成立,那么一次能拿走ai,aj这些全部.问最少拿的次数. 太简单. 乱码 //#pragma comment(lin ...

  4. 【Henu ACM Round#14 C】Duff and Weight Lifting

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 2^y可以由两个2^(y-1)相加得到. 则有一个贪心的策略. 就是2^x尽量都变成2^(x+1) (即能够凑就尽量凑) 如果x还有 ...

  5. 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 ( ...

  6. 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 ...

  7. cf Round 587

    A.Duff and Weight Lifting(思维) 显然题目中只有一种情况可以合并 2^a+2^a=2^(a+1).我们把给出的mi排序一下,模拟合并操作即可. # include <c ...

  8. 2021record

    2021-10-14 P2577 [ZJOI2004]午餐 2021-10-13 CF815C Karen and Supermarket(小小紫题,可笑可笑) P6748 『MdOI R3』Fall ...

  9. PHP实现文字写入图片功能

    /** * PHP实现文字写入图片 */class wordsOnImg { public $config = null; /** * @param $config 传入参数 * @param $co ...

随机推荐

  1. SqlServer2008 设置修改表设计限制

    我记起来了 SQL Server 2008 对操作的安全性进行了限制 你要在Management Studio菜单栏 -工具-选项,弹出选项窗口:把 “阻止保存要求重新创建表的更改” 请的勾去掉.

  2. 《深入理解计算机系统》C程序中常见的内存操作有关的典型编程错误

    对C/C++程序员来说,内存管理是个不小的挑战,绝对值得慎之又慎,否则让由上万行代码构成的模块跑起来后才出现内存崩溃,是很让人痛苦的.因为崩溃的位置在时间和空间上,通常是在距真正的错误源一段距离之后才 ...

  3. bzoj 3105: [cqoi2013]新Nim游戏 异或高消 && 拟阵

    3105: [cqoi2013]新Nim游戏 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 535  Solved: 317[Submit][Stat ...

  4. 李洪强iOS开发之-PCH文件的配置

    pch 可以用来存储共享信息,比如设备屏幕的宽度,高度.版本号等等 公用信息 Xcode 老版本会自动为我们创建pch文件,新版本开始不自动创建了,如果需要使用可以自己手动创建 创建完成后可以在里面定 ...

  5. hdu3006之位压缩

    The Number of set Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. Case swapping

    Case swapping Description: Given a string, swap the case for each of the letters. e.g. CodEwArs --&g ...

  7. css揭秘之linear-gradient

    很神奇的背景设置, 看代码, <html> <title>css</title> <style> .content { background: line ...

  8. linux 失败无连接 检查电缆吗

    将BOOTPROTO=dhcp改成 BOOTPROTO=static 改成手动获取IP的模式 原因: 虚拟机中的Linux目前是默认设成的自动获取IP设置,但你的网络中没有DHCP服务,所以会显示“正 ...

  9. Etcd学习(二)集群搭建Clustering

    1.单个etcd节点(测试开发用) 之前我一直开发测试一直是用的一个Etcd节点,然后启动命令一直都是直接打一个etcd(我已经将etcd安装目录的bin目录加入到PATH环 境变量中),然后启动信息 ...

  10. c#中字符串截取使用的方法

    AndyZhang welcome to java world c#中字符串截取使用的方法 String substring(int beginIndex) String substring(int ...