题意:给你n,x,均不超过10^5,让你构造一个无重复元素的n个元素的非负整数集合(每个元素不超过10^6),使得它们的Xor和恰好为x。

如果x不为0:

  随便在x里面找一个非零位,然后固定该位为0,其他位随意填写,恰好弄出n-1个数来,然后对这n-1个数求xor和,记作sum,再输出x xor sum即可。由于只有最后一个数的该位为1,所以必然可以保证不重。

如果x为0:

  如果n不能被4整除,那么输出0 ~ n-2,然后记这些数的异或和为sum,再输出(1<<18)|sum,以及1<<18即可。

  如果n能被4整除,那么输出1 ~ n-1,然后记这些数的异或和为sum,再输出(1<<18)|sum,以及1<<18即可。

  因为记f(x)=0 xor 1 xor ... xor x,则当且仅当x = 3,7,11,15,...时,f(x)=0。

无解当且仅当n=2,且x=0。

#include<cstdio>
using namespace std;
int n,x;
int main(){
scanf("%d%d",&n,&x);
if(x!=0){
puts("YES");
int I;
for(int i=0;i<=30;++i){
if((x>>i)&1){
I=i;
break;
}
}
int sum=0;
for(int i=0;i<=n-2;++i){
int now=i;
int t=(now^((now>>I)<<I))|((now>>I)<<(I+1));
printf("%d ",t);
sum^=t;
}
printf("%d\n",x^sum);
}
else{
if(n==1){
puts("YES");
puts("0");
return 0;
}
if(n==2){
puts("NO");
return 0;
}
if(n==3){
puts("YES");
puts("1 2 3");
return 0;
}
if((n-2)%4==0){
puts("YES");
int sum=0;
for(int i=1;i<=n-2;++i){
printf("%d ",i);
sum^=i;
}
printf("%d %d\n",(sum|(1<<18)),1<<18);
}
else{
puts("YES");
int sum=0;
for(int i=0;i<n-2;++i){
printf("%d ",i);
sum^=i;
}
printf("%d %d\n",(sum|(1<<18)),1<<18);
}
}
return 0;
}

【构造】【分类讨论】Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor的更多相关文章

  1. 【二分】Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string

    题意:交互题:存在一个至少有一个0和一个1的长度为n的二进制串,你可以进行最多15次询问,每次给出一个长度为n的二进制串,系统返回你此串和原串的海明距离(两串不同的位数).最后要你找到任意一个0的位置 ...

  2. Codeforces Round #435 (Div. 2)【A、B、C、D】

    //在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃 Codeforces Round #435 (Div. 2) codeforces 862 A. M ...

  3. 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root

    题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...

  4. 【Codeforces Round #435 (Div. 2) A B C D】

    CF比赛题目地址:http://codeforces.com/contest/862 A. Mahmoud and Ehab and the MEX ·英文题,述大意:      输入n,x(n,x& ...

  5. Codeforces Round #435 (Div. 2)

    A. Mahmoud and Ehab and the MEX 题目链接:http://codeforces.com/contest/862/problem/A 题目意思:现在一个数列中有n个数,每个 ...

  6. Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary 并查集

    D. Mahmoud and a Dictionary 题目连接: http://codeforces.com/contest/766/problem/D Description Mahmoud wa ...

  7. Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary

    地址:http://codeforces.com/contest/766/problem/D 题目: D. Mahmoud and a Dictionary time limit per test 4 ...

  8. Codeforces Round #396 (Div. 2) E. Mahmoud and a xor trip dfs 按位考虑

    E. Mahmoud and a xor trip 题目连接: http://codeforces.com/contest/766/problem/E Description Mahmoud and ...

  9. Codeforces Round #396 (Div. 2) A. Mahmoud and Longest Uncommon Subsequence 水题

    A. Mahmoud and Longest Uncommon Subsequence 题目连接: http://codeforces.com/contest/766/problem/A Descri ...

随机推荐

  1. Vue 键盘事件

    Vue2键盘事件:keydown/keyup... 1.使用 <!DOCTYPE html> <html> <head> <title></tit ...

  2. 以下suse11.3x64可以安装pycrypto-2.6.1

    rpm -qa adaptec-firmware-1.35-2.15.4gnome-menus-branding-SLED-11.1-14.26man-pages-3.15-2.23.1crackli ...

  3. vs 2015 插件 supercharger 破解方式

    亲测有效:效果如图 方法如下: 1.打开Supercharger的options; 2.点击Pricing & Registration 3.复制 license  然后再按Paste &am ...

  4. LCD 每隔10分钟 自动熄灭 --打开Framebuffer console的时候【转】

    转自:http://blog.csdn.net/liujia2100/article/details/9009063 版权声明:本文为博主原创文章,未经博主允许不得转载. 之前移植LCD的时候,一切正 ...

  5. Laravel 5.2 三、中间件、视图与 Blade 模板引擎

    一.中间件 Laravel 的 HTTP 中间件提供了对路由的一层过滤和保护.下面模拟一下用中间件验证后台登录. 1. 创建中间件 cmd 窗口进入项目目录,使用 artisan 命令创建 php a ...

  6. 2015多校第8场 HDU 5382 GCD?LCM! 数论公式推导

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5382 题意:函数lcm(a,b):求两整数a,b的最小公倍数:函数gcd(a,b):求两整数a,b的最 ...

  7. [ 总结 ] Linux系统启动流程

    Linux系统启动过程分析: 按下电源 --> BIOS自检 --> 系统引导(lilo/grub) --> 启动内核 --> 初始化系统 --> 用户登录 1. BIO ...

  8. MySQL数据库分表分区(一)(转)

    面对当今大数据存储,设想当mysql中一个表的总记录超过1000W,会出现性能的大幅度下降吗? 答案是肯定的,一个表的总记录超过1000W,在操作系统层面检索也是效率非常低的   解决方案: 目前针对 ...

  9. linux命令(43):cal命令

    cal命令可以用来显示公历(阳历)日历.公历是现在国际通用的历法,又称格列历,通称阳历.“阳历”又名“太阳历”,系以地球绕行太阳一周为一年,为西方各国所通用,故又名“西历”. 1.命令格式: cal  ...

  10. classpath中怎样一次性加入整个目录的jar文件

    linux可以通过shell来处理 1 2 3 for jar in $HOME/lib/*.jar; do     CLASSPATH=$CLASSPATH:$jar done