题意:给你两个数x 和 y, x = a + b, y = a XOR b,问有没有合法的a和b满足这个等式?

思路:有恒等式: a + b = ((a & b) << 1) + (a ^ b),所以x - y = ((a & b) << 1), 如果x - y奇数,那就没有合法方案,否则我们可以构造出来.相当于已知a ^ b和a & b, 可以构造一组解了。

代码:

#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;
int main() {
ull x, y, z;
ull ans1 = 0, ans2 = 0;
scanf("%llu%llu", &x, &y);
z = x - y;
if(z & 1) printf("-1\n");
else {
z >>= 1;
for (int i = 0; i < 64; i++) {
if(((z >> i) & 1) == 1) {
ans1 |= (1llu << i);
ans2 |= (1llu << i);
} else {
if(((y >> i) & 1) == 1)
ans2 |= (1llu << i);
}
}
printf("%llu %llu\n", ans1, ans2);
}
}

  

Codeforces 76D 位运算的更多相关文章

  1. Codeforces - 912B 位运算

    求[1,n]内k的值的异或和使其值最大 k=1是肯定是n k>1,设pos是n的最高位,那答案就是(1ll<<(pos+1))-1 这里用到一个性质是当S=2^i-1时,a xor ...

  2. Codeforces 868D Huge Strings - 位运算 - 暴力

    You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...

  3. 图论/位运算 Codeforces Round #285 (Div. 2) C. Misha and Forest

    题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和, ...

  4. Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维

    & -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...

  5. Divide by Zero 2021 and Codeforces Round #714 (Div. 2) B. AND Sequences思维,位运算 难度1400

    题目链接: Problem - B - Codeforces 题目 Example input 4 3 1 1 1 5 1 2 3 4 5 5 0 2 0 3 0 4 1 3 5 1 output 6 ...

  6. CodeForces 282C(位运算)

    C. XOR and OR time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  7. Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] A. Raising Bacteria【位运算/二进制拆分/细胞繁殖,每天倍增】

    A. Raising Bacteria time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #443 (Div. 2) C 位运算

    C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  9. Codeforces 620E New Year Tree(线段树+位运算)

    题目链接 New Year Tree 考虑到$ck <= 60$,那么用位运算统计颜色种数 对于每个点,重新标号并算出他对应的进和出的时间,然后区间更新+查询. 用线段树来维护. #includ ...

随机推荐

  1. springboot: 集成jdbc

    1.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www ...

  2. Eclipse的maven工具

    左侧是组件以及组件依赖树(层级结构):右侧是识别出来的所有的组件:  

  3. bzoj 2597 [Wc2007]剪刀石头布——费用流

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2597 三个人之间的关系,除了“剪刀石头布”,就是有一个人赢了2局:所以考虑算补集,则每个人对 ...

  4. 可以随时查找的max栈和max队列——面试

    这是面试中比较常见的题目,max队列也是编程之美里的一道题 对于max的栈,有个比较简单的办法就是,每次入栈前判断栈顶元素与正在入栈的元素哪个大,哪个大就哪个入栈 对于队列,我们知道可以用两个栈来实现 ...

  5. pheanstalk put 延时队列

    用pheanstalk客户端投放延时任务时,按照文档的参数顺序投放起不到延时的效果,取出(预订)job时data获取的数据也不是投放的字段值, put <pri> <delay> ...

  6. HotSpot Stop-and-Copy GC

    rednaxelafx的Cheney算法的伪代码.如果不用forwarding的话,维护一个旧地址到新地址的映射也可以. 其中重点部分: void Heap::collect() { // The f ...

  7. 微软Azure平台 cloud service动态申请证书并绑定证书碰到的坑

    我们有一个saas平台 部分在azure的cloud service 使用lets encrypt来申请证书.每一个商家申请域名之后就需要通过Lets encrypt来得到证书并绑定证书. 主要碰到的 ...

  8. 一个for循环写出9*9乘法表

    public class ClassTest03 { public static void main(String[] args) { for(int i=1,j=1;j<=9;j++){ if ...

  9. Java运算符,位运算

    注意:位运算符针对整数的补码进行运算,所以运算结果也是补码 &(与运算) 将数据转化为补码形式,然后将0看作false,将1看作true,按位进行与运算,最后将结果转化为十进制来显示     ...

  10. ZOJ 3593 One Person Game(拓展欧几里得求最小步数)

    One Person Game Time Limit: 2 Seconds      Memory Limit: 65536 KB There is an interesting and simple ...