码迷,mamicode.com
首页 > 其他好文 > 详细

51Nod 1596 搬货物

时间:2017-04-25 21:20:52      阅读:218      评论:0      收藏:0      [点我收藏+]

标签: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 }

 

51Nod 1596 搬货物

标签:blog   ble   color   memset   freopen   turn   while   i++   question   

原文地址:http://www.cnblogs.com/zyb993963526/p/6764088.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!