当前位置:网站首页>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 代码
边栏推荐
- js guessing game source code
- "Time Series Database" uses cassandra to scan time series data
- Mobile and PC compatible loading and toast message plugins
- 这些年我开源的几个小项目
- CodeChef STRMRG String Merging (dp)
- L2 applications from a product perspective: why is it a playground?
- 第2章-矩阵及其运算-矩阵创建(1)
- POJ 1026 Cipher (置换群)
- Mount [shell][mount -o loop]
- Redis (three) - detailed configuration file, publish and subscribe, new data types
猜你喜欢

第2章-矩阵及其运算-矩阵运算(2)

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

谷歌数据中心发生“电力事故”造成 3 人受伤
![[Brave food, not afraid of the linked list of brushing questions] Merging of ordered linked lists](/img/06/9d49fc99ab684f03740deb2abc38e2.png)
[Brave food, not afraid of the linked list of brushing questions] Merging of ordered linked lists

What is an abstract class

MLX90640 红外热成像仪测温传感器 手机 APP 软件 RedEye 连接详细

4 面拿华为 offer 的水平,面试阿里居然一面就被吊打?

Several small projects that I have open sourced over the years

3D rotating text animation js special effects

TCP/IP笔记
随机推荐
Pycharm终端出现PS问题、conda或activate不是内部命令问题..
The usage and difference between getParameter() and getAttribute()
ISO9001在讲什么?过程方法和风险思维
动作捕捉系统用于室内组合定位技术研究
使用JMeter进行MySQL的压力测试
leetcode:334. 递增的三元子序列
C#实战:基于ItextSharp技术标签生成小工具
[Azure Cloud] What is the difference between a service endpoint and a private link?point of view (1)
LeetCode_152_乘积最大子数组
From the product dimension, why can't we fully trust Layer2?
PPT | 「课件」企业中高层人员安全管理培训(118页)
使用.NET简单实现一个Redis的高性能克隆版(六)
金九银十跳槽旺季:阿里、百度、京东、美团等技术面试题及答案
[Brave food, not afraid of the linked list of brushing questions] Merging of ordered linked lists
FastReport.Net 2022.2.17 Crack
SQL优化最强总结 (建议收藏~)
MLX90640 红外热成像仪测温传感器 手机 APP 软件 RedEye 连接详细
js guessing game source code
runtime-core.esm-bundler.js?d2dd:218 Uncaught TypeError: formRef.value?.validate is not a function
Three-phase 380V rectified voltage