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 :

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;
}
}
2016 Al-Baath University Training Camp Contest-1 C的更多相关文章
- 2016 Al-Baath University Training Camp Contest-1
2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...
- 2014-2015 Petrozavodsk Winter Training Camp, Contest.58 (Makoto rng_58 Soejima contest)
2014-2015 Petrozavodsk Winter Training Camp, Contest.58 (Makoto rng_58 Soejima contest) Problem A. M ...
- 2016 Al-Baath University Training Camp Contest-1 E
Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...
- 2016 Al-Baath University Training Camp Contest-1 B
Description A group of junior programmers are attending an advanced programming camp, where they lea ...
- 2016 Al-Baath University Training Camp Contest-1 A
Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...
- 2016 Al-Baath University Training Camp Contest-1 J
Description X is fighting beasts in the forest, in order to have a better chance to survive he's gon ...
- 2016 Al-Baath University Training Camp Contest-1 I
Description It is raining again! Youssef really forgot that there is a chance of rain in March, so h ...
- 2016 Al-Baath University Training Camp Contest-1 H
Description You've possibly heard about 'The Endless River'. However, if not, we are introducing it ...
- 2016 Al-Baath University Training Camp Contest-1 G
Description The forces of evil are about to disappear since our hero is now on top on the tower of e ...
- 2016 Al-Baath University Training Camp Contest-1 F
Description Zaid has two words, a of length between 4 and 1000 and b of length 4 exactly. The word a ...
随机推荐
- 封装upload文件上传类
<?php //封装php中的单文件(图片)上传类 /* //参数1:$file 文件数组 5个属性值 name,type,size,tmp,error //参数2:文件保存的路径$pa ...
- paper 49:论文退稿?审稿人帮你总结了22个能避免的常见问题
很多投稿出去的文章都是可上可下的.往往退稿的时候,审稿人提了一堆意见,说退稿.但是大家想过没有?如果能事先预测到这些意见,或者请懂行的人事先看过文章预测出意见,然后根据这些意见修改好了再投出去,说不定 ...
- 取客户的银行帐号SQL
SELECT ibybanks.bank_name, --银行 ibybanks.bank_branch_name, --分行 ibybanks.bank_account_num_electronic ...
- angularjs---$http.post发的数据,后台取不到
我用$http.post(url, data). 后台用play框架,不知道为什么总是取不到data数据.如果直接用$.post(url, data); 就可以! 后台Play的一个action: 打 ...
- python 笔记1
Python join()方法 描述 Python join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串. 语法 join()方法语法: str.join(sequence) 参数 ...
- TP主从服务器配置
在config.php文件中,设置‘DB_DEPLOY_TYPE’=>1,‘DB_HOST’=>‘localhost,192.168.0.1,192.168.0.23’,各个主机之间用逗号 ...
- 【NOIP模拟赛】正方形大阵
正方形大阵 [问题描述] [输入格式] 第一行一个正整数n代表询问次数. 接下来n行每行一个不超过八位的小数k代表一组询问. [输出格式] 输出共n行,代表每次询问的答案:如果有无数个交点 ...
- IE7/8浏览器都不能显示PNG格式图片
方法一:重新注册pngfilt.dll文件.这个方法是PNG格式开发商官方网站上的推荐方法之一,抱着试试的想法按网站推荐的方法试了,一试成功.方法如下:使用 开始->运行,在运行输入框中输入 “ ...
- Java中的get()和set()方法
对于JAVA初学者来说,set和get这两个方法似乎已经很熟悉了,这两个方法是JAVA变成中的基本用法,也是出现频率相当高的两个方法. 如果你对于这两个方法还有困惑甚至完全不知道这两个方法是做什么的, ...
- Eratosthenes筛选法求解质数
问题说明: 除了自身之外,无法被其它整数整除的数称之为质数,要求质数很简单,但如何快速的求出质数则一直是程式设计人员与数学家努力的课题, 在这边介绍一个着名的 Eratosthenes求质数方法. 解 ...