Codeforces Round #326 (Div. 2)587A. Duff and Weight Lifting
来源:互联网 发布:Windows 7定时删除文件 编辑:程序博客网 时间:2024/05/22 06:06
解题报告:Codeforces Round #326 (Editorial)
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 weights2a1, ..., 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 ≤ 106), the number of weights.
The second line contains n integers w1, ..., wn separated by spaces (0 ≤ wi ≤ 106 for each 1 ≤ i ≤ n), the powers of two forming the weights values.
Print the minimum number of steps in a single line.
51 1 2 3 3
2
40 1 2 3
4
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.
题意:输入n个数,w[1]......w[n] . 2a1 + 2a2 + ... + 2ak = 2x, ak 属于那n个数。求有最少多少个这样的x。
- Codeforces Round #326 (Div. 1)A. Duff and Weight Lifting
- Codeforces Round #326 (Div. 1)-A. Duff and Weight Lifting
- Codeforces Round #326 (Div. 2)587A. Duff and Weight Lifting
- codeforces-587A-Duff and Weight Lifting
- Codeforces Round #326 (Div. 2)Problem C - Duff and Weight Lifting
- 【Codeforces Round 326 (Div 2)C】【贪心】Duff and Weight Lifting 每次取数二的幂数最小取数次数
- coderforce 587A Duff and Weight Lifting
- A. Duff and Weight Lifting
- codeblocks round 326 div2 C Duff and Weight Lifting
- Codeforces Round #326 (Div. 2) A. Duff and Meat
- Codeforces Round #326 (Div. 2) 588 A. Duff and Meat
- Codeforces Round #326 (Div. 2) A. Duff and Meat
- Codeforces Round #326 (Div. 2) A. Duff and Meat
- codeforces#326-C-Duff and Weight Lifting-map应用
- Codeforces 588 C. Duff and Weight Lifting
- CodeForces 588 C. Duff and Weight Lifting
- Code Forces 587 A. Duff and Weight Lifting(贪心)
- Code Forces 587 A. Duff and Weight Lifting
- 众数问题
- 黑马程序员——Java基础---IO---Filel类
- swift 2.0 闭包
- 两个android程序间的相互调用传递参数
- Codeforces Round #326 (Div. 2) 588 B. Duff in Love
- Codeforces Round #326 (Div. 2)587A. Duff and Weight Lifting
- C++ 数组的指针,指针的数组, 数组引用
- C语言相关知识
- rpm的制作 spec文件写法
- 算法学习日记--寻找数组中的最大值和最小值
- Fresco(各种特效)——缩放特效
- JavaCC 的安装
- VS中报错 “ Error:未定义标识符 cvRodrigues2“
- linux 下安装flash