下满有详细解析

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

Input

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)

ExampleInput

3
2
10
11
3
110
110
4
1110
1011Output
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).

我给作者 xx点了啦赞, 小心心送给他   (zhuanzia )

  1. 1.两个二进制数的数据范围是100位,用整型类型肯定存不下,用字符串存

  2. 2.题目中要求取余,过程当中是乘法运算,很可能会超出数据范围,所以在每次乘的时候取余

  3. int的取值范围: -2147483648~2147483647 10位

  4. unsigned int的取值范围:0~4294967295

  5. long long的取值范围:-9,223,372,036,854,775,808 到 9,223,372,036,854,775,807 19位

我给作者 OneLine_点了啦赞, 小心心送给他, 作为我借用学习他 的回报。(转载版权声明)

分三种情况讨论

1)同一位上 A和B都为1 那么C可以为0 也可以为1     * 2 是这么来的

2)同一位上 A为1 但B为0 则没有C符合条件               break, sum归零 1 是这么来的

3)同一位上 A和B都为0 C只能为0 或是 A为0 B为1 则C只能为1 (即C只有一种情况) 省略的 sum * 1 是这么来的

将A和B的每一位一一对比讨论 每一位的情况进行相乘 得到所有解的数量

PS:因为最后的数可能会变得很大 所以在每一次相乘的时候 都要对原数进行取模操作

我还是不太了解 按位或运算 , 虽然 哎呀 , 过段时间就理解了

啊, 交个代码 增加个ac数

#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#define INF 0x3f3f3f3f
using namespace std;int main()
{ios::sync_with_stdio(0);int t, n, sum;     // 每次sum * 2 后, sum %MAXN 所以sum可以用int 型string a, b; // char a[1000100]; char b[1000100];cin >> t;while(t--){cin >> n >> a >> b;sum = 1;int flag = 1;for (int i = 0; i < n; i++){if(a[i] == '1' && b[i] == '1')sum *=2;else if(a[i] == '1' && b[i] == '0'){flag = 0;break;}sum %= 1000000007;}if(!flag)cout << "IMPOSSIBLE" << endl;elsecout << sum << endl;}return 0;
}

A or B Equals C Gym - 101028C相关推荐

  1. equals()与hashCode()

    什么是hashCode()? hashCode()的作用是获取哈希码,也称作为散列码.它实际上是返回一个int整数,这个哈希码的作用是确定该对象在哈希表中 索引的位置.hashCode()定义在Obj ...

  2. java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean java.lang.String.equals(j

    今天切正式环境出现的空指针 记录一下 下面是错误 java.lang.NullPointerException: Attempt to invoke virtual method 'boolean j ...

  3. 关于 hashcode 和 equals

    首先需要明白 hashCode() 和equals是Object类中已经被定义好的,所以在java中定义的任何类都有这两个方法.其中原始的equals()方法是用来比较两个对象的地址值,而原始的has ...

  4. 强化学习(三) - Gym库介绍和使用,Markov决策程序实例,动态规划决策实例

    强化学习(三) - Gym库介绍和使用,Markov决策程序实例,动态规划决策实例 1. 引言 在这个部分补充之前马尔科夫决策和动态规划部分的代码.在以后的内容我会把相关代码都附到相关内容的后面.本部 ...

  5. Gym - 102082G

    Gym - 102082G https://vjudge.net/problem/2198225/origin 对于数列中任意一个数,要么从最左边到它不递减,要么从最右边到到它不递减,为了满足这个条件 ...

  6. JAVA-初步认识-第十一章-object类-equals方法覆盖

    一. 现在要谈论equals方法另一个方面.如果不写equals方法,直接用==来比较也是可以的,貌似equals方法有点多余. 现在不比较对象是否相等,而是比较对象中的特定内容,比如说对象的年龄,之 ...

  7. String比较.equals

    首先定义四个变量str public class SIzhui {public static void main(String[] args) {String str1="wang" ...

  8. 【宋红康学习日记11】Object类与equals方法

    1 == (1)当对象是基本数据类型时,比较值: (2)当对象是引用型时,比较的是地址值!!1 2 equals():只处理引用型数据:Object类中的equals方法依然比较的是地址值! 但在St ...

  9. JAVA中重写equals()方法的同时要重写hashcode()方法

    object对象中的 public boolean equals(Object obj),对于任何非空引用值 x 和 y,当且仅当 x 和 y 引用同一个对象时,此方法才返回 true:注意:当此方法 ...

  10. ==和equals()的作用及区别

    "=="的作用是比较两个变量是否相等. 当变量是基本数据类型时,比较的是值是否相等的:相等返回true,不等返回false: double a = 100.0;int b = 10 ...

最新文章

  1. IIS+PHP+MySQL+Zend Optimizer+GD库+phpMyAdmin安装配置[完整修正实用版]
  2. 股市币市:数据分析与交易所最新公告
  3. 七周七并发之线程与锁
  4. ReactJS学习笔记八:动画
  5. 腾讯招.NET,居然要求精通MySQL,而不是SQLServer!
  6. 天池在线编程 2020国庆八天乐 - 6. 山谷序列(DP)
  7. 笨方法“学习python笔记之元组(tuple)
  8. oracle如何检索文件,从Oracle数据库检索文件的示例
  9. java面向对象测试题二_JAVA面向对象-测试题
  10. JavaScript面向对象之Object类型
  11. linux系统快捷键使用
  12. 【Access2007】将Excel表导入至Access2007的当中一张已存在的表之中
  13. 西湖,半含春雨半垂丝
  14. CTF的两道比较不错的流量分析题
  15. 微信拼车小程序无服务器,滴滴顺风车下架 拼车微信小程序笑了
  16. 智源社区AI周刊No.97:Bengio新论文用GFlowNets统一生成模型;北大发布AI for EDA数据集...
  17. html怎么将背景设为黑色,文字设为白色
  18. 《C++ 黑客编程揭秘与防范(第2版)》——6.2 详解PE文件结构
  19. 阿里云编码规范答案_令人沮丧的答案是“我如何开始学习编码?”
  20. 完美世界2018年净利润17亿元 同比增长13.16%

热门文章

  1. 如何用串口助手测试软件485通讯功能,串口调试助手如何检测RS485端口好坏及信号发送的好坏?...
  2. 架构师说低代码:走出半生,归来仍是“毒瘤”!
  3. mr.baidu.com百度官方缩短网址接口网站调用生成制作方法解析
  4. Class not found so assuming code is running on a pre-Java 9 JVM
  5. 控制极限(UCL,LCL) 和规格极限(USL,LSL)
  6. antv/G6使用详细介绍,一篇文章说清antv G6如何使用
  7. 融云 java_融云开发者文档
  8. Python开发技术—面向对象程序设计2
  9. 金融应用,计算酬金 Exercise06_11
  10. 【路径规划】基于遗传算法求解多式联运运输问题matlab源码