题目链接: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 (数学)的更多相关文章

  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 Little Dima and Equation 数学题解

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

  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. Codeforces635C XOR Equation【数学】

    题目链接: http://codeforces.com/contest/635/problem/C 题意: 给定两个数的和s及异或x,求两个数的可能情况. 分析: 我们有公式a+b=a& b∗ ...

  5. CodeForces 635C XOR Equation

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

  6. Codeforces 242E:XOR on Segment(位上的线段树)

    http://codeforces.com/problemset/problem/242/E 题意:给出初始n个数,还有m个操作,操作一种是区间求和,一种是区间xor x. 思路:昨天比赛出的一道类似 ...

  7. Codeforces 617 E. XOR and Favorite Number

    题目链接:http://codeforces.com/problemset/problem/617/E 一看这种区间查询的题目,考虑一下莫队. 如何${O(1)}$的修改和查询呢? 令${f(i,j) ...

  8. Codeforces 617E:XOR and Favorite Number(莫队算法)

    http://codeforces.com/problemset/problem/617/E 题意:给出n个数,q个询问区间,问这个区间里面有多少个区间[i,j]可以使得ai^ai+1^...^aj ...

  9. codeforces 617 E. XOR and Favorite Number(莫队算法)

    题目链接:http://codeforces.com/problemset/problem/617/E 题目: 给你a1 a2 a3 ··· an 个数,m次询问:在[L, R] 里面又多少中 [l, ...

随机推荐

  1. HDU 1160 FatMouse's Speed

    半个下午,总算A过去了 毕竟水题 好歹是自己独立思考,debug,然后2A过的 我为人人的dp算法 题意: 为了支持你的观点,你需要从给的数据中找出尽量多的数据,说明老鼠越重速度越慢这一论点 本着“指 ...

  2. DOM应用

    父级.removeChild(子节点);父级.appendChild(子节点);父级.insertBefore(子节点, 在谁之前); 创建元素: <script> window.onlo ...

  3. HDFS常用命令

    HDFS 常用的文件操作命令 hdfs dfs -text /pub/20151019/1/4/gwmvod/mediags.moretv.com.cn/*.bz2 | wc -l  hdfs dfs ...

  4. POJ 3259 Wormholes【Bellman_ford判断负环】

    题意:给出n个点,m条正权的边,w条负权的边,问是否存在负环 因为Bellman_ford最多松弛n-1次, 因为从起点1终点n最多经过n-2个点,即最多松弛n-1次,如果第n次松弛还能成功的话,则说 ...

  5. 事件类型: 错误 事件来源: Service Control Manager 事件种类: 无 事件 ID: 7000

    在控制面板\管理工具\服务里找dns Client 服务,把他启动了

  6. php延迟加载的示例

    class a{ ; ; //public $d = 5; public function aa(){ echo self::$b; } public function cc(){ echo stat ...

  7. mysql添加索引

    1.添加PRIMARY KEY(主键索引)  mysql>ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` ) 2.添加UNIQUE(唯一索 ...

  8. 实现LoaderCallbacks接口动态循环加载网上图片并展示在手机屏幕上 ...

    1.布局xml文件 activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/re ...

  9. Android中的事件分发和处理

    上次跟大家分享了一下自定义View的一下要点,这次跟大家聊一下View的事件分发及处理,为什么主题都是View,因为作为一名初级应用层Android工程师,跟我打交道最多的莫过于各种各样的View,只 ...

  10. c#枚举自定义,用于数据绑定。 z

    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Enum)] public ...