2016 Al-Baath University Training Camp Contest-1 C
Description
Rami went back from school and he had an easy homework about bitwise operations (and,or,..) The homework was like this : You have an equation : " A | B = C " ( this bar '|' means OR ) you are given the value of A and B , you need to find the value of C ?? as we said before this is an easy question for Rami to solve ,but he wonderd if the equation was like this: " A | C = B " and he is given the value of A and B , how many value of C exists ?? Rami wants your help in this hard question ... He will help you as much as he can ,so he will convert the two decimal numbers(A and B) to binary representaion ( like this: if A=6 –> A=110 ) and this what he knows about OR operation and might be helpfull with your task :
![](http://codeforces.com/predownloaded/4f/7f/4f7f5f45927b98a74f965e96ac9c7c10a9385d71.png)
The input consists of several test cases. The first line of the input contains a single integer T, the number of the test cases. each test case consists of 3 lines : the 1st line is the length of the binary representaion of the 2 numbers.1<=n<=100 the 2nd line is the number A in base 2 .(a string consits of 0s and 1s only ) the 3rd line is the number B in base 2 .(a string consits of 0s and 1s only )
for each test case,you need to print the number of possible values of C that make the eqaution correct in a seperate line .(read page 2 carefully)
3
2
10
11
3
110
110
4
1110
1011
2
4
IMPOSSIBLE
as the answer may be very very large , you should print the answer mod 1000000007. there might be no answer for the equation also , in this case you should print "IMPOSSIBLE" (without qoutes).
题意:A|C==B,问C符合情况的有多少种
解法:1|x=1,x有两种选法,1|x=0不符合规定,输出impossible,其他是一种情况
那么只需要判断1|x=1就行
#include <iostream> #define ll long long using namespace std; int main(){ ll T,mod=1000000007,ans=0; string s1,s2; cin>>T; while(T--){ int n; cin>>n; cin>>s1>>s2; ans=1; for(int i=0;i<n;i++){ if(s1[i]=='1'){ if(s2[i]=='1') ans*=2; else{ ans=-1; break; } } ans%=mod; } if(ans==-1) cout<<"IMPOSSIBLE"<<endl; else cout<<ans<<endl; } }