C. XOR Equation
来源:互联网 发布:我的淘宝等级怎么看 编辑:程序博客网 时间:2024/04/29 21:18
题意:s是a,b之和,x是a,b异或的值。求有多少个a,b对。(a,b为有序队列)
题解:a+b可分解为a^b[个位相加]和(a&b)*2[进位],即a+b=a^b+(a&b)*2.
然后进行2进制枚举。设s=(s-x)/2(即s=a&b).当x(即为a^b)=1时,s必为0,此时a,b有两种取值情况;当x=0时,s的取值决定了最终的a,b取值.具体看代码。
#include <set>#include <map>#include <stack>#include <queue>#include <deque>#include <cmath>#include <vector>#include <string>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define L(i) i<<1#define R(i) i<<1|1#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-9#define maxn 1000100#define MOD 1000000007long long s,x;int main(){ int t; while(scanf("%lld%lld",&s,&x) != EOF) { long long ans = 0; s -= x; if(s % 2 == 1) { printf("0\n"); continue; } s /= 2; int flag = 0,cnt = 0; if(!s) cnt = 2; for(int i = 0; i < 64; i++) { int a1 = s & 1; int a2 = x & 1; if(a1 == 1 && a2 == 1) { flag = 1; break; } s >>= 1; x >>= 1; if(a2 == 0) continue; ans++; } if(flag) printf("0\n"); else printf("%lld\n",(1ll<<ans)-cnt); } return 0;}
0 0
- C. XOR Equation
- CodeForces 635C XOR Equation(数论)
- Codeforces 635C XOR Equation (脑洞)
- CodeForces 635C XOR Equation 数学 公式
- Codeforces 635C XOR Equation【数学姿势】
- HDU4025 Equation of XOR
- 627A.XOR Equation
- Codeforces635C XOR Equation【数学】
- 627A - XOR Equation 数学
- CodeForces 627A XOR Equation
- Codeforces 627A XOR Equation
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) C. XOR Equation
- Codeforces 627A XOR Equation 【数学】
- ♥codeforces 627A-XOR Equation【数学】
- CF 627A. XOR Equation 位运算
- cf#8VC Venture Cup 2016 - Final Round (Div. 2 Edition)-C - XOR Equation-数学/位运算
- CodeForces 627A XOR Equation(异或)
- Codeforces 627A XOR Equation【位运算实现加法】
- 如何在eclipse中查看SHA1的码
- poj3181(高精度完全背包dp)
- 关于php使用基于socket Web消息推送系统
- 汇编(一)汇编语言简介
- 转载 Souces for android api 24 platform not found
- C. XOR Equation
- ios数据存储之--模型对象归档(NSKeyedArchiver、NSKeyedUnarchiver)
- mybatis中的多个参数的问题
- 小议Linux系统下的文件系统
- 分布式中hash取模算法中的问题
- Handler常见用法小结
- sqlserver触发器的使用
- FastDFS简介
- JavaScript强化教程 —— Cocos2d-JS极速调试技巧