Question A: bit computing
Time limit: 1 Sec Memory Limit: 512 MB
Face questions
He declined to publicly face the question.
answer
Simple classification discussion. Or that stupid when classified discussions have come onto the race.
The relations between
AND / OR / XOR
1/1/1: contradiction. 1 with the operation, both of which are 1, 1 is the XOR operation, this bit can not both claim the same.
1/1/0: no contradiction. The same 1 can be. [(1,1) / (1,1) (1,0) (0,1) / (1,1) (0,0)]
1/0/1: contradiction. 1/1/1 same situation.
1/0/0: contradiction.
0/1/1: no contradiction. (0,1) / (1,0) in both cases.
0/1/0: no contradiction. (0,1) / (1,0) in both cases
0/0/1: contradiction.
0/0/0: no contradiction. (0,0) can be.
And / or
0/0: no contradiction. (0,0) can be.
0/1: no contradiction. (1,0) / (0,1) can be.
1/0: contradiction.
1/1: no contradiction. (1,1) can be.
And / XOR
0/0: no contradiction. (0,0) can be.
0/1: no contradiction. (1,0) / (0,1) can be.
1/0: no contradiction. (1,1) can be.
1/1: contradiction.
Or / XOR
0/0: (0, 0).
0/1: contradiction.
1/0: (1,1).
1/1: (1,0) / (0,1).
Code:
#include<bits/stdc++.h> #define rint register int using namespace std; inline void read(long long &a) { a=0;int b=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')b=-1;ch=getchar();} while(ch>='0'&&ch<='9'){a=(a<<3)+(a<<1)+ch-'0';ch=getchar();} a=a*b;return ; } int T; long long ra,ro,rx,ans=1; int main() { scanf("%d",&T); while(T--) { ans=1; read(ra),read(ro),read(rx); if(ro==-1&&rx==-1){puts("inf");continue;} else if(ra==-1&&ro==-1){puts("inf");continue;} else if(ra==-1&&rx==-1) { for(rint i=0;i<=30;++i) if((ro&(1<<i)))ans*=3; printf("%lld\n",ans); continue; } else if(ra==-1) { for(rint i=0;i<=30;++i) { if((ro&(1<<i))&&(rx&(1<<i)))ans<<=1; else if((!(ro&(1<<i)))&&(rx&(1<<i))){ans=0;break;} else if((ro&(1<<i))&&(!(rx&(1<<i))))continue; else continue; } printf("%lld\n",ans); continue; } else if(ro==-1) { for(rint i=0;i<=30;++i) { if((!(ra&(1<<i)))&&(!(rx&(1<<i))))continue; else if((!(ra&(1<<i)))&&(rx&(1<<i)))ans<<=1; else if((ra&(1<<i))&&(!(rx&(1<<i))))continue; else{ans=0;break;} } printf("%lld\n",ans); continue; } else if(rx==-1) { for(rint i=0;i<=30;++i) { if((!(ra&(1<<i)))&&(!(ro&(1<<i))))continue; else if((!(ra&(1<<i)))&&(ro&(1<<i)))ans<<=1; else if((ra&(1<<i))&&(!(ro&(1<<i)))){ans=0;break;} else continue; } printf("%lld\n",ans); } else { for(rint i=0;i<=30;++i) { if(ra&(1<<i)) { if(ro&(1<<i)) { if(rx&(1<<i)){ans=0;break;} else continue; } else{ans=0;break;} } else { if(ro&(1<<i))ans<<=1; else { if(rx&(1<<i)){ans=0;break;} else continue; } } } printf("%lld\n",ans); continue; } } return 0; }