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 ...
随机推荐
- php替换 json符号
- 数据库视图View的使用
一.视图的概念: 概念: 视图是指计算机数据库中的视图,是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据.但是,视图并不在数据库中以存储的数据值集形式存在.行和列数据 ...
- Linux之 xstart调用 x11vnc远程图形化桌面
问题:用 xmanager 中的 xstart 启动界面,报x11无法打开 . 1. root调整x11参数,将其打开[root@localhost ~]# vi /etc/ssh/sshd_conf ...
- angular-ui-bootstrap的弹出框定义成一个服务的实践(二)
定义一个弹出框的服务:alert_box defiine(["app"],function(mainapp){ mainapp.controller('ModalInstanceC ...
- checkstyle简单使用说明
checkstyle对检查代码规范问题的总结,虽然还不够只能,但已经比较强大.1.Cyclomatic Complexity is X (max allowed is X). 问题说明:圈复杂度过高. ...
- Android getevent用法详解
getevent 指令用于获取 input 输入事件,比如获取按键上报信息.获取触摸屏上报信息等. 指令源码路径:/system/core/toolbox/getevent.c getevent -h ...
- warning: backslash and newline separated by space [enabled by default]
警告:反斜杠和换行符之间多了空格. 这种问题出现在宏定义 #define,并且有多行,每行之间要用 “\” 连接起来. 解决办法:删除 “\” 后面的空格,直接紧跟回车.
- VoIP常见编码的带宽计算
voip带宽计算VOIP计算方法与所选用的编码方法有关,而与哪个厂家的没有什么关系,公式如下: 带宽=包长度×每秒包数=包长度×(1/打包周期)=(Ethernet头+IP头+UDP头+RTP头+有效 ...
- java web 程序---登陆验证session。提示登陆
loigin.jsp <%@ page language="java" import="java.util.*" pageEncoding="g ...
- ping正常但是ssh到linux服务器很卡的解决方法
ssh登录很慢的问题 1.关闭ssh DNS反向解析 vi /etc/ssh/sshd_config 修改UseDNS no 2.关闭 GSSAPI 的用户认证 vi /etc/ssh/sshd ...