C. Duff and Weight Lifting

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/588/problem/C

Description

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.

Input

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.

Output

Print the minimum number of steps in a single line.

Sample Input

5
1 1 2 3 3

Sample Output

2

HINT

题意

给你n个数,然后你可以一次性消去一些数,只要满足了2^a1 + 2^a2 + ... + 2^ak = 2^x这个条件就好

题解:

有一个贪心,我们尽量用大的数去换就好了

于是就可以得到下面这个代码啦

代码:

#include<stdio.h>
#include<iostream>
#include<math.h>
#include<map>
#include<cstring>
using namespace std; long long a[];
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
long long x;
scanf("%lld",&x);
a[x]++;
}
long long ans =;
for(int i = ;i<=;i++)
{
ans+=(a[i]&);
a[i+]+=a[i]/;
}
cout<<ans<<endl;
}

Codeforces Round #326 (Div. 2) C. Duff and Weight Lifting 水题的更多相关文章

  1. Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)

    Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...

  2. Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 水题

    C. Efim and Strange Grade 题目连接: http://codeforces.com/contest/719/problem/C Description Efim just re ...

  3. Codeforces Round #185 (Div. 2) A. Whose sentence is it? 水题

    A. Whose sentence is it? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  4. Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 水题

    A. Vitya in the Countryside 题目连接: http://codeforces.com/contest/719/problem/A Description Every summ ...

  5. Codeforces Round #371 (Div. 2) A. Meeting of Old Friends 水题

    A. Meeting of Old Friends 题目连接: http://codeforces.com/contest/714/problem/A Description Today an out ...

  6. Codeforces Round #355 (Div. 2) B. Vanya and Food Processor 水题

    B. Vanya and Food Processor 题目连接: http://www.codeforces.com/contest/677/problem/B Description Vanya ...

  7. Codeforces Round #326 (Div. 2) D. Duff in Beach dp

    D. Duff in Beach Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/probl ...

  8. Codeforces Round #326 (Div. 2) B. Duff in Love 分解质因数

    B. Duff in Love Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/proble ...

  9. Codeforces Round #326 (Div. 2) A. Duff and Meat 水题

    A. Duff and Meat Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/probl ...

随机推荐

  1. Android设计模式之命令模式、策略模式、模板方法模式

    命令模式是其它很多行为型模式的基础模式.策略模式是命令模式的一个特例,而策略模式又和模板方法模式都是算法替换的实现,只不过替换的方式不同.下面来谈谈这三个模式. 命令模式 将一个请求封装为一个对象,从 ...

  2. 给Java新手的一些建议----Java知识点归纳(Java基础部分)

    写这篇文章的目的是想总结一下自己这么多年来使用java的一些心得体会,主要是和一些java基础知识点相关的,所以也希望能分享给刚刚入门的Java程序员和打算入Java开发这个行当的准新手们,希望可以给 ...

  3. mybatis返回HashMap结果类型与映射

    <!-- 返回HashMap结果 类型--> <!-- 如果想返回JavaBean,只需将resultType设置为JavaBean的别名或全限定名 --> <!-- T ...

  4. C++ primer里的template用法

    来源:http://c.chinaitlab.com/cc/ccjq/200806/752604_2.html --  template 的用法    在程序设计当中经常会出现使用同种数据结构的不同实 ...

  5. IOS UIView(UIButton)通过显示动画移动的时候 响应点击的解决方案

    今天在做一个UIButton显示动画的时候,遇到一个问题,就是在移动的时候 ,需要相应它的点击时间(click) 通过CAKeyframeAnimation 来移动UIButton的layer ,效果 ...

  6. 酷派8150S(移动定制版)可用的第三方Recovery备份数据、刷机并精简系统内置APK经验

    希望使用的第三方Recovery下载地址: ClockworkMod ROM Manager - Recoveries http://clockworkmod.com/rommanager 适配的型号 ...

  7. 直接调用系统Camera

    关键思路: 初始化 组件: 创建并启动拍照intent: 使用回调函数onActivityResult()处理图像. 关键代码: 初始化 组件: takePicBtn = (Button) findV ...

  8. SpringMVC+Spring+Hibernate+Maven+mysql整合

    一.准备工作 1.工具:jdk1.7.0_80(64)+tomcat7.0.68+myeclipse10.6+mysql-5.5.48-win322. 开发环境安装配置.Maven项目创建(参考:ht ...

  9. JodaTime用法简介

    JodaTime用法简介 Java的Date和Calendar用起来简直就是灾难,跟C#的DateTime差距太明显了,幸好有JodaTime 本文简单罗列JodaTime的用法 package co ...

  10. labview多个并行循环同时退出

    labview中停止并行的循环 问题: 在labview中我如何停止两个并行的循环?我使用一个局部变量,但是当我停止程序执行后,第二次不能运行程序.我该如何解决这个问题呢? 解答:  你使用局部变量来 ...