当前位置:网站首页>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 代码
边栏推荐
- "Scalability" extensibility best practices: lessons from eBay
- POJ 2891 Strange Way to Express Integers (Extended Euclidean)
- CodeChef STRMRG String Merging (dp)
- 【机器学习】浅谈正规方程法&梯度下降
- js guessing game source code
- 如何使用工程仪器设备在线监测管理系统
- YTU 2894: G--我要去内蒙古大草原
- MongoDB database notes
- 干货!ASSANet:让PointNet++更快更强
- 谷歌数据中心发生“电力事故”造成 3 人受伤
猜你喜欢

bus event bus use

一文带你搞懂中断按键驱动程序之poll机制

Cybersecurity Notes 5 - Digital Signatures

第3章-线性方程组(3)

首次入选OSDI顶会!腾讯提出超大规模推荐系统的模型低延时更新方案

Memory problems difficult to locate, it is because you do not use ASAN

2022年裁员潮,失业程序员何去何从?

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

Research on motion capture system for indoor combined positioning technology

Redis (six) - transaction and lock mechanism of Redis6 (unfinished, to be supplemented)
随机推荐
Short video software development - how to break the platform homogenization
SQL与NoSQL最终会走向融合吗?
PPT | 「课件」企业中高层人员安全管理培训(118页)
L2 applications from a product perspective: why is it a playground?
3 injured in 'electrical accident' at Google data center
Double.doubleToLongBits() method uses
OSSCore 开源解决方案介绍
【机器学习】浅谈正规方程法&梯度下降
How can an organization judge the success of data governance?
干货!ASSANet:让PointNet++更快更强
Kyligence 通过 SOC 2 Type II 审计,以可信赖的企业级产品服务全球客户
Dry goods!ASSANet: Making PointNet++ faster and stronger
第二十二章 源代码文件 REST API 参考(四)
Memory problems difficult to locate, it is because you do not use ASAN
Spss-多元回归案例实操
十年架构五年生活-09 五年之约如期而至
越折腾越好用的 3 款开源 APP
js对象转FormData对象(一般用于上传)
CodeChef STRMRG String Merging (dp)
短视频软件开发——平台同质化如何破局