51nod-1596 搬货物

做了现在才碰到必须用这名为输入挂的东西。。惭愧额。。

思路:

如果能个数为2的倍数就往上合并,否则就单独拿出来

题是简单题,就是输入不一般。

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
using namespace std;
template <class T>
inline void scand(T &ret)
{
    char c;
    ret = 0;
    while ((c = getchar()) < '0' || c > '9');
    while (c >= '0' && c <= '9')
    {
        ret = ret * 10 + (c - '0'), c = getchar();
    }
}
int a[10001005];
int main()
{
    int n;
    scand( n);
    int t;
    for(int i=1;i<=n;i++)
    {
        scand( t);
        a[t]++;
    }
    int ans=0;
    for(int i=0;i<=1001005;i++)
    {
        a[i+1]=a[i+1]+a[i]/2;
        if(a[i]&1)
            ans++;
    }
    cout<<ans<<endl;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值