zoukankan      html  css  js  c++  java
  • 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 :

    Input

    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 )

    Output

    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)

    Example
    input
    3
    2
    10
    11
    3
    110
    110
    4
    1110
    1011
    output
    2
    4
    IMPOSSIBLE
    Note

    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;
    	}
    }
    

      

  • 相关阅读:
    文章评论:级数中达朗贝尔判别法和柯西判别法之间的关系研究 By 彭军
    解析函数论 Page 22 达朗贝尔判别法 VS 柯西判别法
    解析函數論 Page 28 連續復變函數的最簡單的性質
    #2066:一个人的旅行(Dijkstra算法入门题)
    #2072 单词数(字符串流使用)
    传统的DOM渲染方式 吴小明
    【闭包】closure 吴小明
    报文 吴小明
    节流和防抖 吴小明
    什么是模块化?它有什么好处?常用的模块化开发的方案 吴小明
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/6040761.html
Copyright © 2011-2022 走看看