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 ...
随机推荐
- 【Python学习】Jupyter解决单个变量输出问题
使用Jupyter的时候有时候发现,我明明写了好几个变量打印,但是它只显示最后一个.Out只有一个. 但是使用下面的语句.就可以实现多个输出. from IPython.core.interactiv ...
- CiteSeer统计的计算机领域的期刊和会议的影响因子(2005)
产生自CiterSeer 2005数据库,实际的影响因子可能更高.仅供参考使用.真实的IF还需去官网查看 . OSDI: 3.31 (top 0.08%) . USENIX Symposium on ...
- 爬虫===登陆CSDN的方法
本文主要介绍csdn的登陆,可应用在爬虫上~ # -*- coding:utf-8 -*- import json import requestsfrom xlutils.copy import co ...
- HDU 6188 Duizi and Shunzi 贪心
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 题意:给了n个数,然后现在问我们最多构成多少个对子和顺子,其中对子是2个相同的牌,顺子是3个连续 ...
- HTML5API(5)
一.SVG 1.svg与canvas的区别 canvas绘制的是位图,svg绘制的是矢量图 canvas使用JavaScript绘制,svg使用xml绘制 canvas不能给每个图形绑定事件,svg可 ...
- 怎么快速入门一个老的java项目
作者:eilen著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 1.有文档肯定先看文档,先看设计文档,产品的.技术的设计文档,接口文档写的好的可以看看,要是写的不好不着急看. 2 ...
- [ python ] 项目:haproxy配置文件增删改查
1. 开发要求 实现对 haproxy.cfg 增删改查操作 2. 程序介绍 # 作者:hkey # 博客地址:https://www.cnblogs.com/hukey/p/9288279.html ...
- 让IE6支持css3,让 IE7、IE8 都支持CSS3
但凡是前端工程师,都知道IE6,IE7,IE8不支持.或者不完全支持CSS3的属性. CSS3 有很多很强大.绚丽的效果,比如,圆角,阴影,渐变透明,渐变背景,等等. 因为IE6时代,没有什么标准,而 ...
- linux命令(26):ls命令
例一:列出/home/peidachang文件夹下的所有文件和目录的详细资料 ls -l -R /home/test 例二:列出当前目录中所有以“t”开头的目录的详细内容,可以使用如下命令: ls - ...
- connect-falsh的用法
借鉴博客 http://yunkus.com/connect-flash-usage/