Codeforces 76D 位运算
题意:给你两个数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 位运算的更多相关文章
- Codeforces - 912B 位运算
求[1,n]内k的值的异或和使其值最大 k=1是肯定是n k>1,设pos是n的最高位,那答案就是(1ll<<(pos+1))-1 这里用到一个性质是当S=2^i-1时,a xor ...
- Codeforces 868D Huge Strings - 位运算 - 暴力
You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...
- 图论/位运算 Codeforces Round #285 (Div. 2) C. Misha and Forest
题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和, ...
- 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 ...
- 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 ...
- CodeForces 282C(位运算)
C. XOR and OR time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 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 ...
- Codeforces Round #443 (Div. 2) C 位运算
C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces 620E New Year Tree(线段树+位运算)
题目链接 New Year Tree 考虑到$ck <= 60$,那么用位运算统计颜色种数 对于每个点,重新标号并算出他对应的进和出的时间,然后区间更新+查询. 用线段树来维护. #includ ...
随机推荐
- bzoj1025(SCOI2009)游戏——唯一分解的思路与应用
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1025 可以认为对应的值之间连边,就连成了一个有一个或几个环的图.列数就是每个环里点数的lcm ...
- nginx应用编译安装
nginx应用编译安装: 安装编译所需依赖包: # apt-get install make gcc g++ libcurl3-openssl-dev libfreetype6-dev libmcry ...
- jdk1.8新特性应用之Iterable
我们继续看lambda表达式的应用: public void urlExcuAspect(RpcController controller, Message request, RpcCallback ...
- RK3288 HDMI配置和调试
RK3288 最大输出分辨率为 3840x2160 HDMI 驱动代码位于 kernel/drivers/video/rockchip/hdmi/rockchip-hdmiv2 目录 1.设置默认输出 ...
- Jenkins的项目管理
新建Item 使用Jenkins最重要的是能够创建一些工作流,除了部署,还能做很多流程上的事情.同样,一条条项目建起来需要做一定的管理,在Jenkins首页Jenkins->新建可以按自己的需要 ...
- struts2学习(3)struts2核心知识II
一.struts.xml配置: 1.分模块配置方法: 比如某个系统多个模块,我们把资产管理模块和车辆管理模块,分开,在总的struts.xml配置文件中include他们: 工程结构: struts. ...
- python 将html实体转回去
参考资料: http://www.360doc.com/content/17/0620/16/44530822_664927373.shtml https://blog.csdn.net/guzhou ...
- 为什么 JSON 接口的数据都要加双引号!!!不能用单引号
原因是:Javascript 在很多时候会把 JSON 对象里面没有双引号包围的值,当做数值处理.比如: {"a":987654321} 这个 JSON 里头的变量 a,会被当做一 ...
- POJ1159解题心得
题目:http://poj.org/problem?id=1159 刚开始,从样例的特征去思考.总让我从回文数的角度去思考,想出几个方案,可都用了数据去检验,发现不行.如:ABCDDCB,BACDCA ...
- node中一个基本的HTTP客户端向本地的HTTP服务器发送数据
上一篇讲到了node可以轻松的向其他请求数据. 这一篇就来讲讲向本地服务器的数据交互. HTTP服务器代码,s.js var http=require("http"); var s ...