题目描述:
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there’s no more weight left. Malek asked her to minimize the number of steps.
Duff is a competitive programming fan. That’s why in each step, she can only lift and throw away a sequence of weights 2a1, …, 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + … + 2ak = 2x, i. e. the sum of those numbers is a power of two.

Duff is a competitive programming fan, but not a programmer. That’s why she asked for your help. Help her minimize the number of steps.
输入描述:
The first line of input contains integer n (1 ≤ n ≤ 10610^6106), the number of weights.

The second line contains n integers w1, …, wn separated by spaces (0 ≤ wi ≤ 10610^6106 for each 1 ≤ i ≤ n), the powers of two forming the weights values.
输出描述:
Print the minimum number of steps in a single line.
输入:
5
1 1 2 3 3
4
0 1 2 3
输出:
2
4
Note
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it’s not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It’s not possible to do it in less than 4 steps because there’s no subset of weights with more than one weight and sum equal to a power of two.
题意:
两个1合成一个2,两个2合成一个3,两个3合成一个4,以此类推,问最后剩下数的个数
题解
统计各个数的个数,按两个1合成一个2的思路,直接暴力枚举,时间复杂度O(n),水题。
代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;const int maxn = 2000000 + 5;
int a[maxn],x;int main(){int n;while(scanf("%d",&n)!=EOF){memset(a,0,sizeof(a));for(int i = 0; i < n; i ++){scanf("%d",&x);a[x] ++;}int ans = 0;for(int i = 0; i <= 2000000; i ++){a[i + 1] += a[i] / 2;if(a[i] % 2) ans ++;}cout<<ans<<endl;}return 0;
}

Codeforces--1311A--Duff and Weight Lifting相关推荐

  1. Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting

    B. Pasha and Phone Pasha has recently bought a new phone jPager and started adding his friends' phon ...

  2. Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting

    B. Pasha and Phone Pasha has recently bought a new phone jPager and started adding his friends' phon ...

  3. 【CodeForces - 298D】Fish Weight (OAE思想,思维)

    题干: It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sor ...

  4. Codeforces 827D Best Edge Weight 倍增 + 并查集 || 倍增 + 压倍增标记 (看题解)

    Best Edge Weight 我们先找出一棵最小生成树, 对于非树边来说, 答案就是两点路径上的最大值 - 1, 这个直接倍增就能处理. 对于树边来说, 就是非树边的路径经过这条边的最小值 - 1 ...

  5. SCAU-春季训练-不应该啊(怎么这么菜。。。)

    2021/3/14 春季训练2(难度div2d) 反思:(赛前,看什么crt,赛时满脑子都是线性方程组,....................................) 最近表现都不太好.. ...

  6. material-ui_满足Material-UI —您最喜欢的新用户界面库

    material-ui by Code Realm 通过Code Realm 满足Material-UI -您最喜欢的新用户界面库 (Meet Material-UI - your new favor ...

  7. keras 香草编码器_完善纯香草javascript中的拖放

    keras 香草编码器 Drag-and-drop functionality is the bread and butter of a modern web UX. It's an aspect o ...

  8. 编写代码的软件用什么编写的_如何通过像编写代码一样克服对编写的恐惧

    编写代码的软件用什么编写的 by Chris Rowe 通过克里斯·罗 How often do you get the fear? What do I mean by fear? How about ...

  9. PhoneGap插件入门(转)

    PhoneGap插件概述 PhoneGap有两部分组成 1.PhoneGap javascript API,即 对在浏览器(支持各种浏览器)上运行的javascript公开的一些原始功能的API 2. ...

  10. 我的AI之路(55)--如何获取kinetics数据集和如何制作自己的kinetics数据集

    近来做行为动作识别,根据近两年的CVPR.ICCV.ECCV论文实验了一序列的动作识别方面的模型,很多都用到了kinetics数据集或者something-something数据集,但是后者的官网目前 ...

最新文章

  1. usagestatsmanager获取正在运行应用_用Python构建数据科学Web应用程序
  2. 打印机更换感光鼓单元k_干货,激光打印机常见故障维修方法总结
  3. Java面试题:Java垃圾收集有哪些算法,AQS组件总结
  4. 算法:Validate Binary Search Tree(验证二叉查找树)
  5. 深度解读 AlphaGo 算法原理
  6. ubuntu安装wps后缺少字体无法打开
  7. mysql 5.7 临时表_MySQL 5.7内部临时表使用
  8. 用C++计算圆周长和面积
  9. php使用逻辑运算符提交程序运行效率
  10. 安卓平板隐藏虚拟按键_Android 4.0 虚拟按键、手机模式、平板模式
  11. python 高级部分
  12. 徐家骏是华为数据中心的头,技术超级牛人,一级部门总监,华为副总裁,年收入过千万。
  13. 潦草字体在线识别_连笔字在线生成器
  14. SSD可靠性影响因素、原理和解决方法
  15. 爱读掌阅java版_爱读掌阅app官方下载-爱读掌阅旧版本 - 超好玩
  16. 微信小程序实现蓝牙打印(图片、二维码、文字)
  17. 解决问题最简单的方法
  18. Excel 2016新增图表攻略
  19. python爬虫四:爬取贴吧数据
  20. 企业考勤管理系统python_用Python编写一个电子考勤系统!谁还敢迟到?

热门文章

  1. python爬取链家_Python爬取链家北京二手房数据
  2. excel 组合框控件使用方法
  3. 汽车电子电气TARA分析从入门到放弃
  4. ai 分形艺术_作为艺术家的AI?
  5. MySQL设计一个图书馆数据库_设计一个图书馆数据库
  6. 自媒体行业的发展和前景
  7. 虚拟机中Ubuntu安装中文输入法(谷歌输入法)
  8. N卡和A卡有什么区别?A卡和N卡的区别,一个动图秒懂
  9. 免费申请国外免费域名保姆级教程
  10. acme申请泛域名证书