当前位置:网站首页>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 代码
边栏推荐
- Open Office XML 格式里如何描述多段具有不同字体设置的段落
- Regarding the missing json converter, the error message is: No converter found for return value of type
- MLX90640 红外热成像仪测温传感器 手机 APP 软件 RedEye 连接详细
- bus event bus use
- GPU加速Pinterest推荐模型,参数量增加100倍,用户活跃度提高16%
- The brave rice rice, does not fear the brush list of 】 list has a ring
- 【电商运营】你真的了解社交媒体营销(SMM)吗?
- 突破次元壁垒,让身边的玩偶手办在屏幕上动起来!
- Codeforces 814 C. An impassioned circulation of affection (dp)
- The impact of development mode on testing
猜你喜欢
这些年我开源的几个小项目
振弦传感器及核心VM系列振弦采集模块
如何使用工程仪器设备在线监测管理系统
STM32 encapsulation ESP8266 a key configuration function: implementations of AP mode and the STA mode switch, server and the client to create
Network Security Note 6 - Digital Certificates and Public Key Infrastructure
Redis6 (1) - Introduction to NoSQL Database and Installation of Redis
C#实战:基于ItextSharp技术标签生成小工具
Redis(六)——Redis6的事务和锁机制(未完成,待补)
【勇敢饭饭,不怕刷题之链表】链表反转的几种情况
Weilai-software development engineer side record
随机推荐
Short video software development - how to break the platform homogenization
Redis(六)——Redis6的事务和锁机制(未完成,待补)
GPU accelerated Pinterest recommendation model, the number of parameters increased by 100 times, and the user activity increased by 16%
Gold, nine, silver and ten job-hopping seasons: technical interview questions and answers on Alibaba, Baidu, JD.com, and Meituan
Text selection rounded style border-radius
The brave rice rice, does not fear the brush list of 】 list has a ring
Open Office XML 格式里如何描述多段具有不同字体设置的段落
mysql出现:ERROR 1524 (HY000): Plugin ‘123‘ is not loaded
AUTOCAD - reducing spline curve control points, the advanced CAD practice (3)
PPT | 「课件」企业中高层人员安全管理培训(118页)
Several small projects that I have open sourced over the years
C#实战:基于ItextSharp技术标签生成小工具
[Azure Cloud] What is the difference between a service endpoint and a private link?point of view (1)
Gartner再次重申了“数据编织”的重要价值
[Brave food, not afraid to write the linked list] The problem of the penultimate node of the linked list
Three-phase 380V rectified voltage
【勇敢饭饭,不怕刷题之链表】链表中有环的问题
第5章相似矩阵及二次型(4)
【勇敢饭饭,不怕刷题之链表】有序链表的合并
第2章-矩阵及其运算-矩阵创建(1)