Codeforces635C XOR Equation【数学】
来源:互联网 发布:北京交通大学知行pt 编辑:程序博客网 时间:2024/05/30 04:33
题目链接:
http://codeforces.com/contest/635/problem/C
题意:
给定两个数的和s及异或x,求两个数的可能情况。
分析:
我们有公式
这样对于与和异或的结果一位一位的来考虑即可。
注意:
- 题目特别强调Two positive integers a and b,所以在
s 与x 相等时,我们要减去0的情况。 - 差为奇数的情况很明显不存在ab。
- 按位判断的时候注意xx和tt都为1的情况也是不存在的。
代码:
#include<cstdio>#include<iostream>#include<cstring>using namespace std;#define pr(x) cout << #x << ": " << x << " "#define pl(x) cout << #x << ": " << x << endl;#define sa(x) scanf("%d",&(x))#define sal(x) scanf("%I64d",&(x))#define mdzz cout<<"mdzz"<<endl;const int maxn = 2e5 + 5, oo =0x3f3f3f3f;typedef long long ll;//a + b = a & b * 2 + a ^ bint main (void){ ll s, x;sal(s);sal(x); ll t = s - x; if(t & 1) return puts("0"),0; t >>= 1; int tt = 1, xx = 1; ll ans = 1; ll tx = x; while(t || x){ tt = t & 1; xx = x & 1; if(!tt && xx) ans <<= 1; if(tt && xx) return puts("0"), 0; t >>= 1; x >>= 1; } if(s == tx) ans -= 2; printf("%I64d", ans); return 0;}
0 0
- Codeforces635C XOR Equation【数学】
- 627A - XOR Equation 数学
- Codeforces 627A XOR Equation 【数学】
- ♥codeforces 627A-XOR Equation【数学】
- CodeForces 635C XOR Equation 数学 公式
- Codeforces 635C XOR Equation【数学姿势】
- HDU4025 Equation of XOR
- 627A.XOR Equation
- C. XOR Equation
- CodeForces 627A XOR Equation
- Codeforces 627A XOR Equation
- cf#8VC Venture Cup 2016 - Final Round (Div. 2 Edition)-C - XOR Equation-数学/位运算
- Non-square Equation 数学
- CodeForces 635C XOR Equation(数论)
- CF 627A. XOR Equation 位运算
- Codeforces 635C XOR Equation (脑洞)
- CodeForces 627A XOR Equation(异或)
- Codeforces 627A XOR Equation【位运算实现加法】
- 训练1-5
- 一辈子太短,遗憾却太多
- 动态删除Fragment只能用FragmentStatePagerAdapter
- jquery easyui datagrid 分页实现
- IOS文件操作的两种方式:NSFileManager操作和流操作
- Codeforces635C XOR Equation【数学】
- String 类的subString(),indexof(),lastindexof()的用法
- 在linux下配置java版本方便切换
- 东北大学研究生造机器人去桃核 图像识别术与去核动作结合
- AFNetworking报错"_UTTypeCopyPreferredTagWithClass", referenced from: _AFContentTypeForPathExtens
- Ant如何打包UIAutomator项目用到的第三方JAR包
- 【JS 设计模式 】门面模式之DOM元素绑定事件
- vim中project插件安装与使用
- 进程和线程的区别