当前位置:网站首页>Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)
Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)
2022-08-10 10:54:00 【51CTO】
Description
Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won’t show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets.
Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to find a set of n distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly x. Dr. Evil doesn’t like big numbers, so any number in the set shouldn’t be greater than 10^6.
Input
The only line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the set and the desired bitwise-xor, respectively.
Output
If there is no such set, print “NO” (without quotes).
Otherwise, on the first line print “YES” (without quotes) and on the second line print n distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them.
Examples input
Examples output
题意
寻找 n 个不同的数,且这些数的异或值等于 x
思路
开个脑洞就可以想到
除了 n=2,x=0
当 n=1 时显然直接输出 x 即可, n=2 时解为 0,x
对于其他情况下,保留三个数,其中两个可以中和掉相应位,而另一个数对最终结果做出贡献。
我们令 pr=1<<17 ,代表一个大于 n 的数,最终结果中我们假设包含 1,2,3...n−3 ,且这些数的异或值为 y
如果 x=y ,则说明这 n−3 个数已经保证了答案,那剩下的三个数只要异或值等于 0 即可,于是很方便找到 pr⊕(pr×2)⊕(pr⊕(pr×2))=0
对于 x!=y 时,剩下的三个数 0⊕pr⊕(pr⊕x⊕y) 可以保证它与之前的 y 异或等于 x
AC 代码
边栏推荐
- 干货!ASSANet:让PointNet++更快更强
- what is bsp in rtems
- 从产品角度看 L2 应用:为什么说这是一个游乐场?
- 不止跑路,拯救误操作rm -rf /*的小伙儿
- owl.carousel poster card Slider carousel switch
- OneFlow source code parsing: operator instructions executed in a virtual machine
- Introduction to cross-end development of Taro applet
- Gold, nine, silver and ten job-hopping seasons: technical interview questions and answers on Alibaba, Baidu, JD.com, and Meituan
- Hangdian Multi-School-Loop-(uncertainty greedy + line segment tree)
- POJ 3101 Astronomy (Mathematics)
猜你喜欢

Gold, nine, silver and ten job-hopping seasons: technical interview questions and answers on Alibaba, Baidu, JD.com, and Meituan

1-IMU参数解析以及选择

让软件飞——“X+”技术揭秘

OneFlow source code parsing: operator instructions executed in a virtual machine

GPU accelerated Pinterest recommendation model, the number of parameters increased by 100 times, and the user activity increased by 16%

内存问题难定位,那是因为你没用ASAN

"Chief Engineer" Principal (Principal) engineer's way of training

C#实战:基于ItextSharp技术标签生成小工具

Emulate stm32 directly with proteus - the programmer can be completely discarded

关于振弦采集模块及采集仪振弦频率值准确率的问题
随机推荐
what is bsp in rtems
TCP/IP笔记
POJ 1026 Cipher (置换群)
owl.carousel poster card Slider carousel switch
企业如何判断数据治理是否成功?
1-IMU参数解析以及选择
程序员追求技术夯实基础学习路线建议
【勇敢饭饭,不怕刷题之链表】有序链表的合并
Codeforces 814 C. An impassioned circulation of affection (dp)
Will SQL and NoSQL eventually converge?
【勇敢饭饭,不怕刷题之链表】链表倒数节点问题
Hangdian Multi-School-Loop-(uncertainty greedy + line segment tree)
4 of huawei offer levels, incredibly side is easing the bit in the interview ali?
Introduction to cross-end development of Taro applet
开发模式对测试的影响
从产品维度来看 我们为什么不能完全信任Layer2?
Kyligence 通过 SOC 2 Type II 审计,以可信赖的企业级产品服务全球客户
Open Office XML 格式里如何描述多段具有不同字体设置的段落
"Chief Engineer" Principal (Principal) engineer's way of training
EasyCVR级联时,修改下级平台名称将不同步至上级平台