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

      

  • 相关阅读:
    用Java实现一个简单的DBMS(总结)
    Android小记(整理一下自己犯过的错误)
    在华为云上开启FTP服务并建立FTP站点来从本地向服务器发送和下载文件
    AS中使用真机调试时出现解析错误的问题
    AS中加载gradle时出现Gradle sync failed: Could not find com.android.tools.build:gradle.的错误
    解决AS加载gradle时出现的Could not find com.android.tools.build:gradle:3.5.0.的错误
    过滤器
    View的呈现
    Asp.net MVC Action同步异步执行
    Model验证
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/6040761.html
Copyright © 2011-2022 走看看