探索flutter框架开发的app在移动应用市场的潜力与挑战
898
2022-10-03
Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)
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
5 5
Examples output
YES1 2 4 5 7
题意
寻找 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 代码
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~