coderforce 587A Duff and Weight Lifting

题意:给一个数n,下面有n个数wi,如果sum(2^wi)==2^x(x是整数),那么就给结果 ans 加一次,min(ans);
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxm=1e7;
int a[maxm];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int x,sum=0;
        memset(a,0,sizeof(a));
        for(int i=0;i<n;i++)
        {
            scanf("%d",&x);
            a[x]++;
        }
        for(int i=1;i<=maxm;i++)
        {
            sum+=(a[i-1]%2);
            a[i]+=a[i-1]/2;
        }
        printf("%d\n",sum);
    }
    return 0;
}

你可能感兴趣的:(coderforce 587A Duff and Weight Lifting)