题目链接:

http://codeforces.com/contest/635/problem/C

题意:

给定两个数的和s及异或x,求两个数的可能情况。

分析:

我们有公式a+b=a& b∗2+a ^ b

这样对于与和异或的结果一位一位的来考虑即可。

注意:

  1. 题目特别强调Two positive integers a and b,所以在s与x相等时,我们要减去0的情况。
  2. 差为奇数的情况很明显不存在ab。
  3. 按位判断的时候注意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 ^ b
int 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;
}

Codeforces635C XOR Equation【数学】的更多相关文章

  1. 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 integ ...

  2. Codeforces 627 A. XOR Equation (数学)

    题目链接:http://codeforces.com/problemset/problem/627/A 题意: 告诉你s 和 x,a + b = s    a xor b = x   a, b > ...

  3. Codeforces 627A XOR Equation(思路)

    题目大概说两个正整数a.b,已知s=a+b以及x=a xor b的值,问有几种a.b这样的数对. 我知道异或相当于无进位的加法,s-x就是其各个位置的进位,比如s-x=1010,那就表示a和b的第1位 ...

  4. hdu 5344 MZL's xor(数学之异或)

    Problem Description   MZL loves xor very much.Now he gets an array A.The length of A ≤i,j≤n) The xor ...

  5. Codeforces Little Dima and Equation 数学题解

    B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...

  6. CF627A Xor Equation

    题意:a+b=s,a^b=x(异或).问有多少有序Z+对(a,b)满足条件. 标程: #include<cstdio> using namespace std; typedef long ...

  7. CodeForces 635C XOR Equation

    位运算. 又涨姿势了:$a + b = (aXORb) + 2*(aANDb)$,$ (aXORb)$是不进位的部分,$2*(aANDb)$为进位之后的部分,相加就是$a + b$. 知道了这个转换, ...

  8. UVA12716 GCD XOR 数论数学构造

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u010682557/article/details/36204645 题目给你一个N,让你求 两个数 ...

  9. 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 ...

随机推荐

  1. LeetCode之Weekly Contest 93

    第一题:二进制间距 问题: 给定一个正整数 N,找到并返回 N 的二进制表示中两个连续的 1 之间的最长距离. 如果没有两个连续的 1,返回 0 . 示例 1: 输入:22 输出:2 解释: 22 的 ...

  2. vue.js笔记1.0

    事件: 事件冒泡行为: 1.@click="show($event)" show:function (ev) { ev.cancelBubble=true; } 2.@click. ...

  3. 通过源码编译安装VIM

    开发中使用的是Ubuntu 12.04 LTS,通过sudo apt-get install vim安装的版本较低,不支持YCM,所以,用源码编译并安装最新的Vim. 卸载旧版本的Vim: sudo ...

  4. python基本操作(四)

    与用户交互 为什么交互? 计算机取代人类,解放劳动力 如何交互 print('-'*100) input('请输入你的姓名:') print(""100) Python2和Pyth ...

  5. socket中send和recv函数

    Socket一次Recv接受的字节有限制么? 从套接字接收数据. 返回值是表示接收数据的字符串. 一次接收的最大数据量由bufsize指定.它默认为零. 注意为了最好地匹配硬件和网络现实,bufsiz ...

  6. 下拉列表 Spinner

    在Web开发中,HTML提供了下拉列表的实现,就是使用<select>元素实现一个下拉列表,在其中每个下拉列表项使用<option>表示即可.这是在Web开发中一个必不可少的交 ...

  7. 29、在android中采用动画方案来弹出窗口

    1.自定义style 2.使用方法: buttonWhat.setOnClickListener(new OnClickListener() { @Override public void onCli ...

  8. 了解CSS核心精髓(一)

    CSS 1.css外联 正确写法:<link rel="stylesheet" href="css/style.css" /> <style ...

  9. day05_05 for循环、break语句

    1.0 输入用户名,密码练习 _user = "alex" _passwd = "abc123" username = input("Username ...

  10. Emacs 安装与体验

        Emacs 安装与体验 下载与安装 首先是下载最新的x64版本的Emacs. 将下载下来的文件解压到你喜欢的磁盘目录下,我选择的是C:\Program Files.放在D盘可能是更好的选择,因 ...