题意:给你两个数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. #231-D: declaration is not visible outside of function

    通常出现在.h中的函数声明,函数声明中的变量用到了.h当中没有的变量形式,比如特殊定义的结构体

  2. 【转】Ubuntu中Vmware Tools的安装与卸载

    原文网址:http://blog.csdn.net/huanghe423/article/details/7005611 Vmware Tools是VMware提供的一套非常人性化的程序,可以用来解决 ...

  3. CentOS yum源设定使用方法的整理(转)

    CentOS yum更新了很多版本更新,我本人认为CentOS yum很好使的文件系统,在此向大家推荐CentOS应该是做为服务器的linux的佼佼者.CentOS采用的二进制包是rpm,不过包的依赖 ...

  4. IIS注册Framework4.0

    打开iis,确认一下framework4.0是否已经安装. 开始->控制面板->管理工具->Internet信息服务->应用程序池(左边栏)->观察右边主界面.net f ...

  5. 数组与指针的区别,以及在STL中传递数组/指针

    数组和指针在作为实参传入T[] 或T*的形参时没有区别 void f(int pi[]) { cout << sizeof(pi) << endl; } int a[5] = ...

  6. bzoj1729: [Usaco2005 dec]Cow Patterns 牛的模式匹配

    Description     约翰的N(1≤N≤100000)只奶牛中出现了K(1≤K≤25000)只爱惹麻烦的坏蛋.奶牛们按一定的顺序排队的时候,这些坏蛋总会站在一起.为了找出这些坏蛋,约翰让他的 ...

  7. java代码---------实现布尔型的功能,是否执行下一步的关键

    总结:灵活 package com.sads; import java.io.BufferedReader; import java.io.IOException; import java.io.In ...

  8. 第十章 Secret & Configmap (上)

    敏感信息,直接保存在容器镜像中显然不妥,比如用户名.密码等.K8s提供的解决方案是Secret. Secret会以密文的方式存储数据,避免了在配置文件中保存敏感信息.Secret会以Volume的形式 ...

  9. node中的require

    /*在node中,可以使用require()函数来加载模块. * require函数使用一个参数,参数值可以带有完整路径的模块的文件名,也可以为模块名.当使用node中提供的模块时,在require函 ...

  10. JAVA中构造函数的参数传递给类中的实例变量

    class VolcanoRobot1 { String status; int speed; float temperature; VolcanoRobot1(int speed,float tem ...