Codeforces 627 A. XOR Equation (数学)
题目链接:http://codeforces.com/problemset/problem/627/A
题意:
告诉你s 和 x,a + b = s a xor b = x a, b > 0。 让你求符合条件的a b有多少对
思路:
a + b = s , a ^ b = x ==> s - x = (a & b) * 2
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[], b[];
int main()
{
LL s, x;
cin >> s >> x;
LL y = s - x;
if(y % || x > s) {
cout << << endl;
} else {
y /= ;
int pos1 = , pos2 = , cnt = , fuck = y ? : ;
for( ; x; ++pos1, x >>= ) {
if(x & ) {
++cnt;
a[pos1] = ;
}
}
for( ; y; ++pos2, y >>= ) {
if(y & )
b[pos2] = ;
}
int ok = ;
for(int i = ; i < max(pos1, pos2); ++i) {
if(a[i] && b[i]) {
ok = ;
break;
}
}
if(ok) {
if(fuck) {
cout << (1LL << ((LL)cnt)) << endl;
} else {
cout << (1LL << ((LL)cnt)) - << endl;
}
} else {
cout << << endl;
}
}
return ;
}
Codeforces 627 A. 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 Little Dima and Equation 数学题解
B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces 627A XOR Equation(思路)
题目大概说两个正整数a.b,已知s=a+b以及x=a xor b的值,问有几种a.b这样的数对. 我知道异或相当于无进位的加法,s-x就是其各个位置的进位,比如s-x=1010,那就表示a和b的第1位 ...
- Codeforces635C XOR Equation【数学】
题目链接: http://codeforces.com/contest/635/problem/C 题意: 给定两个数的和s及异或x,求两个数的可能情况. 分析: 我们有公式a+b=a& b∗ ...
- CodeForces 635C XOR Equation
位运算. 又涨姿势了:$a + b = (aXORb) + 2*(aANDb)$,$ (aXORb)$是不进位的部分,$2*(aANDb)$为进位之后的部分,相加就是$a + b$. 知道了这个转换, ...
- Codeforces 242E:XOR on Segment(位上的线段树)
http://codeforces.com/problemset/problem/242/E 题意:给出初始n个数,还有m个操作,操作一种是区间求和,一种是区间xor x. 思路:昨天比赛出的一道类似 ...
- Codeforces 617 E. XOR and Favorite Number
题目链接:http://codeforces.com/problemset/problem/617/E 一看这种区间查询的题目,考虑一下莫队. 如何${O(1)}$的修改和查询呢? 令${f(i,j) ...
- Codeforces 617E:XOR and Favorite Number(莫队算法)
http://codeforces.com/problemset/problem/617/E 题意:给出n个数,q个询问区间,问这个区间里面有多少个区间[i,j]可以使得ai^ai+1^...^aj ...
- codeforces 617 E. XOR and Favorite Number(莫队算法)
题目链接:http://codeforces.com/problemset/problem/617/E 题目: 给你a1 a2 a3 ··· an 个数,m次询问:在[L, R] 里面又多少中 [l, ...
随机推荐
- [转] 解析Qt资源文件使用
解析Qt资源文件使用 转自:http://mobile.51cto.com/symbian-270121.htm 本文详细的介绍了Qt文件的使用,和大部分GUI框架设计工具一样,Qt也引入了资源文件系 ...
- 如何使用USB安装XenServer 6.x
在XenServer 5.6以前我们能够很容易的通过一些工具,直接制作USB安装介质,然后快速安装XenServer,但是我们发现,到XenServer6.0以后,通过工具直接制作的XenServer ...
- PHP中括号“{}”的3个作用
1,将多个独立语句合并为一个复合语句,例如“if .... else ....”中推荐如此使用. 2,在变量的间接引用中进行定界,避免歧义.例如“${$my_var[8]}”与“${$my_var}[ ...
- 07day2
居然是动规专场.这样不好吧? 采药 [问题描述] 辰辰是个天资聪颖的孩子,他的梦想是成为世界上最伟大的医师.为此,他想拜附近最有威望的医师为师.医师为了判断他的资质,给他出了一个难题.医师把他带到 ...
- HDU 2026 首字母变大写
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int ma ...
- ORA-00257错误
Archiver error,connect internal only,until freed 表示归档日志目录已满,用户不能再连接数据库,现有用户可继续查询数据库,但是不能执行DML语句 插删 ...
- MySQL5.6 ALTER TABLE 分析和测试
在MySQL5.5和之前版本,在运行的生产环境对大表(超过数百万纪录)执行Alter操作是一件很困难的事情.因为将重建表和锁表,影响用户者的使用.因此知道Alter操作何时结束对我们是非常重要的.甚至 ...
- RegEx正则表达式学习笔记
一.实用的例子 public static void main(String[] args) { // 简单练习 System.out.println("-123".matches ...
- MySQL · 性能优化· InnoDB buffer pool flush策略漫谈
MySQL · 性能优化· InnoDB buffer pool flush策略漫谈 背景 我们知道InnoDB使用buffer pool来缓存从磁盘读取到内存的数据页.buffer pool通常由数 ...
- C# 导出一个控件的矢量图
调用Control.DrawToBitmap(Bitmap) 方法是很容易得到控件的图形的. 但是bitmap是栅格化图形.栅格化图形有很多缺点,比如文件体积比较大. 放大后失真. 不易编辑等等. 这 ...