587A
#include<iostream> #include<algorithm> #include<stdio.h> #include<stdlib.h> #include<string.h> using namespace std; const int maxn=1e7+9;//数组必须开大些,因为数据过大时2^n会超过1e6; int w[maxn]; int n,ans; int main() { while(~scanf("%d",&n)) { memset(w,0,sizeof(w)); ans=0; for(int i=0;i<n;i++) { int x; scanf("%d",&x); w[x]++; //x代表幂 } for(int i=1;i<maxn;i++) //合并;原理:2^n+2^n=2^(n+1); { w[i]+=(w[i-1]/2); w[i-1]%=2; } for(int i=0;i<maxn;i++) ans+=w[i]; printf("%d\n",ans); } return 0; }