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

acdream 1154 Lowbit Sum

时间:2014-07-31 20:26:37      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   for   代码   div   

先贴代码,以后再写题解。。。

 

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <algorithm>
 5 using namespace std;
 6 
 7 typedef long long ll;
 8 
 9 ll s[100];
10 
11 ll init (int n){
12     if (s[n])
13         return s[n];
14     s[n]=init (n-1)*2-(1<<(n-1))+(1<<n);//cout<<s[n]<<" ";
15     return s[n];
16 }
17 
18 int main (){
19     int n;    //while (cin>>n&&n) cout<<(1024>>n)<<endl;
20     ll ans=1;
21     int temp=2;
22     memset (s,0,sizeof s);
23     s[0]=1;
24     init (30);    //for (int i=0;i<=30;i++) cout<<s[i]<<" ";
25     while (~scanf ("%d",&n)){
26         ans=0;
27         for (int i=0;n&&i<30;i++) {
28             if (n&1)
29                 ans+=s[i];//cout<<ans<<endl;
30             n>>=1;
31             //n/=2;
32         }
33         printf ("%lld\n",ans);
34     }
35     return 0;
36 }

 

acdream 1154 Lowbit Sum,布布扣,bubuko.com

acdream 1154 Lowbit Sum

标签:style   blog   color   os   io   for   代码   div   

原文地址:http://www.cnblogs.com/gfc-g/p/3881293.html

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