【构造】【分类讨论】Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor
题意:给你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的更多相关文章
- 【二分】Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string
题意:交互题:存在一个至少有一个0和一个1的长度为n的二进制串,你可以进行最多15次询问,每次给出一个长度为n的二进制串,系统返回你此串和原串的海明距离(两串不同的位数).最后要你找到任意一个0的位置 ...
- Codeforces Round #435 (Div. 2)【A、B、C、D】
//在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃 Codeforces Round #435 (Div. 2) codeforces 862 A. M ...
- 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...
- 【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& ...
- Codeforces Round #435 (Div. 2)
A. Mahmoud and Ehab and the MEX 题目链接:http://codeforces.com/contest/862/problem/A 题目意思:现在一个数列中有n个数,每个 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- flask函数已定义参数却出现takes 0 positional arguments but 1 was given的问题
在flask中定义了一个简单的删除数据库内容的路由 测试却发现一直报错 说delete_history函数定义时没有接受参数,但是检查delete_history函数却发现没有问题 后来想了半天才发现 ...
- ASP.NET 设置DropDownList的当前选项
1.通过显示字符Text DropDownList.Items.FindByText("你的值").Selected=true; 如果在设置之前,进行过设置,应用如下格式: Dro ...
- ”未能加载文件或程序集“Oracle.DataAccess”或它的某一个依赖项
引用:http://www.cnblogs.com/joey0210/archive/2012/09/29/2708420.html 上一篇文章说到了DLL引用问题,主要是说的程序中如果使用过了反射, ...
- [转]python os模块 常用命令
python编程时,经常和文件.目录打交道,这是就离不了os模块.os模块包含普遍的操作系统功能,与具体的平台无关.以下列举常用的命令 1. os.name()——判断现在正在实用的平台,Window ...
- 以下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 ...
- Linux 入门记录:十四、网络基础
一.IP地址 IP 地址是因特网上的每个网络节点在全球范围内的唯一标识符,一个 IP 地址唯一标识一个主机(严格来说是标识一个网卡接口 network interface card). 现在应用最为广 ...
- python基础===解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX(转载)
本文转自:解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX 从网上抓了一些字 ...
- ogre3d环境配置 SDK安装配置及简单事例教程
ogre3d环境配置 SDK安装配置及简单事例教程 http://www.cr173.com/html/22594_1.html ogre3d环境配置 SDK安装配置及简单事例教程 http://ww ...
- C# 读写XML文件示例
using System; using System.Collections.Generic; using System.Text; using System.Configuration; using ...
- 2016多校第4场 HDU 6076 Security Check DP,思维
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6076 题意:现要检查两条队伍,有两种方式,一种是从两条队伍中任选一条检查一个人,第二种是在每条队伍中同 ...