标签:blog ble color memset freopen turn while i++ question
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1596
思路:
模拟二进制的进位。
这题很坑啊...用c++会超时,用c就行了...
1 #include<stdio.h> 2 #include<string.h> 3 4 const int maxn=1e6+1000; 5 6 int w[maxn]; 7 8 int main() 9 { 10 //freopen("D:\\input.txt","r",stdin); 11 int n; 12 while(scanf("%d",&n)!=EOF) 13 { 14 memset(w,0,sizeof(w)); 15 int x; 16 while(n--) 17 { 18 scanf("%d",&x); 19 w[x]++; } 20 int sum=0; 21 for(int i=0;i<maxn;i++) 22 { 23 if(w[i]>1) 24 { 25 w[i+1]+=w[i]/2; 26 w[i]%=2; 27 } 28 if(w[i]==1) sum++; 29 } 30 printf("%d\n",sum); 31 } 32 return 0; 33 }
标签:blog ble color memset freopen turn while i++ question
原文地址:http://www.cnblogs.com/zyb993963526/p/6764088.html