題目連接:http://acm.hdu.edu.cn/showproblem.php?pid=5491php
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1118 Accepted Submission(s): 446
ios
1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 long long ans,t,n,nu,mi,ma,c[50],j,s; 7 long long fina() 8 { 9 long long sum=c[0],te=1; 10 for (int i=1;i<=33;i++) 11 { 12 te*=2; 13 sum=sum+te*c[i]; 14 } 15 return sum; 16 } 17 int main() 18 { 19 20 //cin>>t; 21 scanf("%lld",&t); 22 for (int cas=1;cas<=t;cas++) 23 { 24 //cin>>nu>>mi>>ma; 25 scanf("%lld%lld%lld",&nu,&mi,&ma); 26 nu++; 27 ans=nu; 28 memset(c,0,sizeof(c)); 29 j=0,s=0; 30 while (nu!=0) 31 { 32 if (nu%2) 33 s++; 34 c[j++]=nu%2; 35 nu/=2; 36 } 37 j--; 38 while (1) 39 { 40 if (s>=mi&&s<=ma) 41 { 42 43 //cout <<"Case #"<<cas<<": "<<fina()<<endl; 44 printf("Case #%d: %lld\n",cas,fina()); 45 break; 46 } 47 if (s<mi) 48 { 49 for (int i=0;;i++) 50 { 51 if (c[i]==0) 52 { 53 c[i]=1; 54 s++; 55 break; 56 } 57 } 58 } 59 else 60 { 61 int i=0; 62 while (c[i]==0) 63 i++; 64 c[i]++; 65 while (c[i]==2) 66 { 67 c[i]=0; 68 s--; 69 c[i+1]++; 70 i++; 71 } 72 s++; 73 } 74 } 75 } 76 return 0; 77 }