当前位置:网站首页>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 代码
边栏推荐
猜你喜欢
商城限时秒杀功能系统
L2 applications from a product perspective: why is it a playground?
从产品维度来看 我们为什么不能完全信任Layer2?
leetcode:334. 递增的三元子序列
使用cpolar远程连接群晖NAS(升级固定链接2)
Introduction to cross-end development of Taro applet
Automated Testing and Selenium
From the product dimension, why can't we fully trust Layer2?
Open Office XML 格式里如何描述多段具有不同字体设置的段落
2022年裁员潮,失业程序员何去何从?
随机推荐
【机器学习】浅谈正规方程法&梯度下降
程序员追求技术夯实基础学习路线建议
runtime-core.esm-bundler.js?d2dd:218 Uncaught TypeError: formRef.value?.validate is not a function
From the product dimension, why can't we fully trust Layer2?
TCP/IP笔记
第2章-矩阵及其运算-矩阵创建(1)
短视频软件开发——平台同质化如何破局
从脚本到剪辑,影像大师亲授的后期制作秘籍
网络文化经营许可证
快速上手,征服三种不同分布式架构调用方案
FastReport.Net 2022.2.17 Crack
[Brave food, not afraid to write the linked list] The problem of the penultimate node of the linked list
LeetCode_152_乘积最大子数组
AUTOCAD - reducing spline curve control points, the advanced CAD practice (3)
Dry goods!ASSANet: Making PointNet++ faster and stronger
Gold, nine, silver and ten job-hopping seasons: technical interview questions and answers on Alibaba, Baidu, JD.com, and Meituan
POJ 3101 Astronomy (Mathematics)
Codeforces 814 C. An impassioned circulation of affection (dp)
Programmers pursue technology to consolidate basic learning route suggestions
Emulate stm32 directly with proteus - the programmer can be completely discarded