题意:给你两个数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. asciidoctor 安装试用

    备注:    asciidoctor 是asciidoc 的增强,使用简单,模板比较丰富,对于持续集成方面的开发也是一个不错的工具   1. 安装 a. 环境准备 MRI Ruby 1.8.7, 1. ...

  2. caddy server && caddyfile

    This page describes how to configure Caddy using the Caddyfile. Introduction The term "Caddyfil ...

  3. 对两个奇葩的C语言程序的思考

    原文章的连接为:http://www.cnblogs.com/jacksu-tencent/default.html?page=2 1. 第一个程序例如以下: #include <stdio.h ...

  4. SPI: Service Provider Interface

    Service Provider Interface: JDK提供的一种服务发现的机制:主要是用于厂商实现JDK的只用. 比如说打印机,JDK提供了一个驱动接口com.printl.printerDr ...

  5. linq左连接

    Table1和Table2连接,把Table1的全列出来 var tempData = from a in table1 join b in table2 on a.Id equals b.aId i ...

  6. linux下踢出已登录用户

    通过xshell登录到linux,看到如下所示,有3个用户,但是前面两个不知在哪登录的了,那就踢出吧. 先确认一下自己是哪个 顺便注意一下“whoami”和“who am i”的不同 然后踢出前面两个 ...

  7. Linux c- libevent

    libevent是一个事件触发的网络库,适用于windows.linux.bsd等多种平台,内部使用select.epoll.kqueue等系统调用管理事件机制.著名分布式缓存软件memcached也 ...

  8. Type-C潮流下 如何衡量一款数据线好坏?

    不少新一代手机开始支持Type-C接口,比如乐视.PPTV.努比亚Z11.小米4C和三星Note7等.和普通Micro USB相比,Type-C数据线因为正反插的关系对品质要求更高,不然随时有短路烧毁 ...

  9. 【BZOJ】3524 [POI2014] Couriers(主席树)

    题目 传送门:QWQ 传送到洛谷QWQ 分析 把求区间第k大的改一改就ok了. 代码 #include <bits/stdc++.h> using namespace std; ; ], ...

  10. oracle 11g密码永不过期

    ---1.在CMD命令窗口中输入: sqlplus 用户名/密码@数据库本地服务名 as sysdba; ---2.查看用户的proifle是哪个,一般是default sql>SELECT u ...