连续的比特 (Bits,UVa 11645)

 1 #include <iostream>
 2 #include <string.h>
 3 #include <string>
 4 #include <fstream>
 5 #include <algorithm>
 6 #include <stdio.h>
 7 #include <vector>
 8 #include <queue>
 9 #include <set>
10 #include <cmath>
11 using namespace std;
12 const double eps = 1e-8;
13 const double pi=acos(-1.0);
14 const int INF=0x7fffffff;
15 unsigned long long uINF = ~0LL;
16 #define MAXN 10000007
17 typedef long long LL;
18 LL a,b;
19 void Plus(LL x)
20 {
21     b+=x;//cout<<x<<endl;
22     if(b>=(1000000000000ll))
23     {a+=b/(1000000000000ll);
24     b%=(1000000000000ll);}
25 }
26 int main()
27 {
28     LL n,t=1;
29     while(scanf("%lld",&n),n!=-1)
30     {
31         a=b=0;
32         LL temp=n;
33         LL dig=1;
34         while(n>1)
35         {
36             Plus((n>>2)*dig);
37             if((n&3)==3)
38                 Plus((temp&(dig-1))+1);
39             dig<<=1;
40             n>>=1;
41         }
42         printf("Case %d: ",t++);
43         if(a)
44         {
45             printf("%lld",a);
46             printf("%012lld
",b);
47         }
48         else printf("%lld
",b);
49     }
50 
51     return 0;
52 }

和 UVa 11038 类似 按位计算

原文地址:https://www.cnblogs.com/TO-Asia/p/3214706.html