标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 332 Accepted Submission(s): 135
昨天的B题,我的理解力,我都惭愧了,自己写了好几个样例才完全搞懂。
从最高位到最低位贪心。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<queue> 6 #include<algorithm> 7 using namespace std; 8 typedef long long ll; 9 void solve(){ 10 int t; 11 scanf("%d",&t); 12 while(t--){ 13 ll a,b,c,d; 14 cin>>a>>b>>c>>d; 15 int x1,x2,y1,y2; 16 ll ans = 0; 17 for(int i = 63; i>=0; i--){ 18 x1 = (bool)(a&((ll)1<<i)); 19 x2 = (bool)(b&((ll)1<<i)); 20 y1 = (bool)(c&((ll)1<<i)); 21 y2 = (bool)(d&((ll)1<<i)); 22 if(x1 == x2&&y1 == y2){ 23 if(x1 != y1){ 24 ans += ((ll)1<<i); 25 } 26 } 27 else if(x1 != x2&&y1 == y2){ 28 ans += ((ll)1<<i); 29 if(y1 == 1){ 30 b = ((ll)1<<i) - 1; 31 } 32 else{ 33 a = ((ll)1<<i); 34 } 35 } 36 else if(x1 == x2&&y1 != y2){ 37 ans += ((ll)1<<i); 38 if(x1 == 1){ 39 d = ((ll)1<<i) - 1; 40 } 41 else{ 42 c = ((ll)1<<i); 43 } 44 } 45 else if(x1 != x2&&y1 != y2){ 46 ans += ((ll)1<<(i+1))-1; 47 break; 48 } 49 } 50 cout<<ans<<endl; 51 } 52 } 53 int main() 54 { 55 solve(); 56 return 0; 57 }
标签:
原文地址:http://www.cnblogs.com/littlepear/p/5376626.html