8VC Venture Cup 2016 - Final Round (Div. 2 Edition) C. XOR Equation 数学
C. XOR Equation
题目连接:
http://www.codeforces.com/contest/635/problem/C
Description
Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)?
Input
The first line of the input contains two integers s and x (2 ≤ s ≤ 1012, 0 ≤ x ≤ 1012), the sum and bitwise xor of the pair of positive integers, respectively.
Output
Print a single integer, the number of solutions to the given conditions. If no solutions exist, print 0.
Sample Input
9 5
Sample Output
4
Hint
题意
给你两个数的和,以及两个数的异或结果,问你有多少个数对a,b满足要求
题解:
首先你要知道 a+b = a&b*2 + a^b,这个东西是递归加法的定义
所以你就知道了a&b和a^b,然后根据这两个东西对于数字的每一位进行讨论就好了
如果a^b = 1,那么a&b必须等于0,否则肯定不对嘛,这时候,ai=1 bi=0,ai=0 bi=1有两种选择
如果a^b = 0,那么a&b = ai = bi,只有一种选择
所以答案就是2的a^b中1的个数次方。当然,最后还得判一判s==x的情况,这种情况得把0的情况给剖去。
代码
#include<bits/stdc++.h>
using namespace std;
long long s,x;
int flag = 0;
int main()
{
cin>>s>>x;
if(s==x)flag = 1;
s-=x;
if(s%2==1)return puts("0");
s/=2;
long long ans = 1;
for(int i=0;i<60;i++)
{
int p1 = (s>>i)&1;
int p2 = (x>>i)&1;
if(p2==1&&p1==1)return puts("0");
if(p2==1)ans*=2;
}
if(flag)ans-=2;
cout<<ans<<endl;
}
8VC Venture Cup 2016 - Final Round (Div. 2 Edition) C. XOR Equation 数学的更多相关文章
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)
暴力 A - Orchestra import java.io.*; import java.util.*; public class Main { public static void main(S ...
- 8VC Venture Cup 2016 - Final Round (Div. 1 Edition) E - Preorder Test 树形dp
E - Preorder Test 思路:想到二分答案了之后就不难啦, 对于每个答案用树形dp取check, 如果二分的值是val, dp[ i ]表示 i 这棵子树答案不低于val的可以访问的 最多 ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A
A. Orchestra time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) D. Factory Repairs 树状数组
D. Factory Repairs 题目连接: http://www.codeforces.com/contest/635/problem/D Description A factory produ ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)B. sland Puzzle 水题
B. sland Puzzle 题目连接: http://www.codeforces.com/contest/635/problem/B Description A remote island ch ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A. Orchestra 水题
A. Orchestra 题目连接: http://www.codeforces.com/contest/635/problem/A Description Paul is at the orches ...
- Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) E - Nikita and stack 线段树好题
http://codeforces.com/contest/760/problem/E 题目大意:现在对栈有m个操作,但是顺序是乱的,现在每输入一个操作要求你输出当前的栈顶, 注意,已有操作要按它们的 ...
- Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) D - Travel Card
D - Travel Card 思路:dp,类似于单调队列优化. 其实可以写的更简单... #include<bits/stdc++.h> #define LL long long #de ...
- Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition)A 水 B 二分 C并查集
A. Petr and a calendar time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
随机推荐
- java===java基础学习(10)---对象构造
重载 如果多个方法有相同的名字,不同的参数,便产生了重载.编译器必须挑选出具体执行哪个方法,他通过用各个方法给出的参数类I型那个与特定方法调用所使用的值类型进行匹配来挑选出相应的方法.如果编译器找不到 ...
- appium===使用weditor代替ui automator viewer
weditor 一个元素定位工具,并可实现通过wifi连接移动端进行定位. https://github.com/openatx/uiautomator2 python安装方式: pip instal ...
- python基础===理解Class的一道题
解题如下: from random import randint class Die(): def __init__(self,sides=6): self.sides = sides def rol ...
- CSS原生布局方式
前言 网页原生布局的方法其实网上有很多,大概为Flow(流动布局模型).Float(浮动布局模型).Layer(层级布局模型).<!--more--> Flow布局 流动布局模型其实就是默 ...
- Python构造函数使用
1. 子类不定义构造函数时候,默认引用父类构造函数 class A(object): def __init__(self,name): self.name = name def run(self): ...
- linux下查看机器配置
查看cpu信息:lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): ...
- js字符串与Unicode编码互相转换
).toString() "597d" 这段代码的意思是,把字符'好'转化成Unicode编码,toString()就是把字符转化成16进制了 看看charCodeAt()是怎么个 ...
- redis之(十二)redis数据的持久化
[一]redis的数据为什么要持久化 --->redis的存取数据性能高,是由于将所有数据都存储在内存中.当redis重启的时候,存储在内存中的数据就容易丢失. --->把redis作为数 ...
- Java学习笔记(二)——Java操作properties文件
[前面的话] 前段时间在学习和玩java web相关的东西,对于这些技术,一边学习,一边做东西,一边总结,希望可以一边成长和有所收获.有时总是思考太多反而成为了前进的阻力,所以对于生活还是简单一些,不 ...
- NodeJs中使用jQuery?
在NodeJs中使用jQuery? 有时候在项目中需要使用jq在node中,但是使用起来却不是那么友好,那么现在该怎么做?改写JQ插件?将JQ插件打包成npm包,再在项目中进行引用?显然这些相比较于难 ...