Codeforces635C XOR Equation【数学】
题目链接:
http://codeforces.com/contest/635/problem/C
题意:
给定两个数的和s及异或x,求两个数的可能情况。
分析:
我们有公式a+b=a& b∗2+a ^ b
这样对于与和异或的结果一位一位的来考虑即可。
注意:
- 题目特别强调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 ^ 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【数学】的更多相关文章
- 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 ...
- Codeforces 627 A. XOR Equation (数学)
题目链接:http://codeforces.com/problemset/problem/627/A 题意: 告诉你s 和 x,a + b = s a xor b = x a, b > ...
- Codeforces 627A XOR Equation(思路)
题目大概说两个正整数a.b,已知s=a+b以及x=a xor b的值,问有几种a.b这样的数对. 我知道异或相当于无进位的加法,s-x就是其各个位置的进位,比如s-x=1010,那就表示a和b的第1位 ...
- 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 ...
- Codeforces Little Dima and Equation 数学题解
B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...
- CF627A Xor Equation
题意:a+b=s,a^b=x(异或).问有多少有序Z+对(a,b)满足条件. 标程: #include<cstdio> using namespace std; typedef long ...
- CodeForces 635C XOR Equation
位运算. 又涨姿势了:$a + b = (aXORb) + 2*(aANDb)$,$ (aXORb)$是不进位的部分,$2*(aANDb)$为进位之后的部分,相加就是$a + b$. 知道了这个转换, ...
- UVA12716 GCD XOR 数论数学构造
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u010682557/article/details/36204645 题目给你一个N,让你求 两个数 ...
- 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 ...
随机推荐
- 【mysql】The server quit without updating PID file
groupadd mysql useradd -r -g mysql mysql cd /usr/local/mysql chown -R mysql:mysql . scripts/mysql_ ...
- Python3学习了解日记
# 单行注释 ''' 多行注释 ''' """ 这个也是多行注释 """ ''' 声明变量 Python 中的变量不需要声明.每个变量在使用 ...
- 安装ubuntu16.4后
美化及配置: http://www.fant0m.com/18.html 安装pip: $ wget https://bootstrap.pypa.io/get-pip.py $ python get ...
- hdu1787 GCD Again poj 2478 Farey Sequence 欧拉函数
hdu1787,直接求欧拉函数 #include <iostream> #include <cstdio> using namespace std; int n; int ph ...
- 剑指offer算法编程题目部分汇总(解法略)
总结一下本书中遇到的大部分面试题.面试题3:二维数组中的查找 题目:在一个二维数组中,每一行都按照从左到右的递增顺序排列,每一列都按照从上到下递增的顺序排列,请完成一个函数,输入这样的一个整数,判断数 ...
- ogre3D学习基础10 -- 键盘控制与鼠标控制(缓冲控制)
带缓冲的鼠标.键盘操作,这里的鼠标.按键事件会被各自的监听器捕获.其中OIS中定义的两个类MouseListener,KeyListener负责对事件的处理.我们需要使用这两个类的接口. 当一个键被按 ...
- Zend Framework 2中如何使用Service Manager
end Framework 2 使用ServiceManager(简称SM)来实现控制反转(IoC).有很多资料介绍了service managers的背景,我推荐大家看看this blog post ...
- windows :Tomcat免安装版环境变量配置 + jdk配置
1. 下载后解压,我解压的目录为:D:\Tomcat\apache-tomcat-9.0.1-windows-x64 2. 安装jdk和jre, 并配置环境变量: 2.1 用户变量新建JAVA_H ...
- [python学习篇][书籍学习][python standrad library][内置类型]对象测试真值,布尔值操作, 比较操作
几乎所有对象都可以比较.测试真值.转换为字符串(其实就是用repr()函数,或略有差异的str()函数来转换) 1 对象是否为真 任何对象都可以测试真值,用于if或while的条件或下面布尔运算的操作 ...
- 九度oj 题目1362:左旋转字符串(Move!Move!!Move!!!)
题目描述: 汇编语言中有一种移位指令叫做循环左移(ROL),现在有个简单的任务,就是用字符串模拟这个指令的运算结果.对于一个给定的字符序列S,请你把其循环左移K位后的序列输出.例如,字符序列S=”ab ...