题意:要求构造一个n个数的序列,要求n个数互不相同,且异或结果为x。

分析:

1、因为0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ (0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ x) = x,

构造的n个数可以为0,1,2,3,...,(n - 3),(n - 2),(0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ x)。

2、因为(0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ x)可能与0,1,2,3,...,(n - 3),(n - 2)中某个数重复,因此可以通过将某两个数| (1 << 17)来避免重复。

这两个数,一个可以选择(0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ x),另一个可以选择与(0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ x)不同的某个数。

3、如果(0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ x)与n-2相同,则n-3一定与(0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ x)不同,因此将n-3和(0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ x)同时| (1 << 17)来避免重复。

如果(0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ x)与n-2不同,则将n-2和(0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ x)同时| (1 << 17)来避免重复。

4、因为n最大为105,二进制为11000011010100000,共17位,所以将某两个数| (1 << 17),最高位可以相互抵消,又可以使n个数互不相同。

因为106是20位,所以将某两个数| (1 << 17)后是18位,不会超过106,符合题意。

5、特判一下n=1以及n=2&&x=0即可。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 10000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
vector<int> ans;
int main(){
int n, x;
scanf("%d%d", &n, &x);
if(n == 1){
printf("YES\n");
printf("%d\n", x);
return 0;
}
if(n == 2){
if(x == 0){
printf("NO\n");
}
else{
printf("YES\n");
printf("0 %d\n", x);
}
return 0;
}
int tmp = 0;
for(int i = 0; i <= n - 2; ++i){
tmp ^= i;
}
tmp ^= x;
if(tmp == n - 2){
for(int i = 0; i <= n - 4; ++i){
ans.push_back(i);
}
ans.push_back((n - 3) | (1 << 17));
ans.push_back(n - 2);
ans.push_back(tmp | (1 << 17));
}
else{
for(int i = 0; i <= n - 3; ++i){
ans.push_back(i);
}
ans.push_back((n - 2) | (1 << 17));
ans.push_back(tmp | (1 << 17));
}
printf("YES\n");
int len = ans.size();
for(int i = 0; i < len; ++i){
if(i) printf(" ");
printf("%d", ans[i]);
}
printf("\n");
return 0;
}

  

CodeForces - 862C Mahmoud and Ehab and the xor(构造)的更多相关文章

  1. CodeForces - 862C Mahmoud and Ehab and the xor(构造)【异或】

    <题目链接> 题目大意: 给出n.m,现在需要你输出任意n个不相同的数(n,m<1e5),使他们的异或结果为m,如果不存在n个不相同的数异或结果为m,则输出"NO" ...

  2. Codeforces 862C - Mahmoud and Ehab and the xor

    862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了 ...

  3. 862C - Mahmoud and Ehab and the xor(构造)

    原题链接:http://codeforces.com/contest/862/problem/C 题意:给出n,x,求n个不同的数,使这些数的异或和为x 思路:(官方题解)只有n==2&&am ...

  4. Coderfroces 862 C. Mahmoud and Ehab and the xor

    C. Mahmoud and Ehab and the xor Mahmoud and Ehab are on the third stage of their adventures now. As ...

  5. Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  6. Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)

    Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...

  7. Codeforces 862A Mahmoud and Ehab and the MEX

    传送门:CF-862A A. Mahmoud and Ehab and the MEX time limit per test 2 seconds memory limit per test 256 ...

  8. Codeforces 862B - Mahmoud and Ehab and the bipartiteness

    862B - Mahmoud and Ehab and the bipartiteness 思路:先染色,然后找一种颜色dfs遍历每一个点求答案. 代码: #include<bits/stdc+ ...

  9. Codeforces 862D. Mahmoud and Ehab and the binary string (二分)

    题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...

随机推荐

  1. push 、pop 、unshift 、shift

    push .pop : 操作数组后面 unshift .shift :操作数组前面 push.unshift : 字母多的添加 pop .shift : 字母少的删除 push.unshift : 添 ...

  2. 转载--centos7.4安装docker

    参考博文:https://www.cnblogs.com/yufeng218/p/8370670.html 作者:风止雨歇 Docker从1.13版本之后采用时间线的方式作为版本号,分为社区版CE和企 ...

  3. CSS - 权重,样式优先级

    关于CSS权重,一套计算公式来去计算,就是 CSS Specificity,我们称为CSS 特性或称非凡性,它是一个衡量CSS值优先级的一个标准. 遇到样式应用问题,计算一下权重就知道优先级. 具体规 ...

  4. http调用之RestTemplate

    核心方法为org.springframework.web.client.RestTemplate.doExecute(URI, HttpMethod, RequestCallback, Respons ...

  5. 第九届蓝桥杯B组决赛 调手表(完全背包)

    问题描述 M78 星云的一个小时有 n 分钟. 大家都知道,手表只有一个按钮可以把当前的数加一.在调分钟的时候,如果当前显示的数是 0 ,那么按一下按钮就会变成 1,再按一次变成 2 .如果当前的数是 ...

  6. 内核运行时数据结构的操作(启用路由功能),sysctl内核设置命令

    LINUX系统运行时,内核数据结构数据的修改,系统提供了统一抽象的文件操作接口(命名空间操作接口)比如启用路由功能echo  1 > proc/sys/net/ipv4/ip-forward// ...

  7. Css——设置input输入框光标颜色

    在使用 input 输入框时,我们可能会遇到需要给其设置光标颜色的情况.谷歌浏览器的默认光标颜色是黑色的,GitHub 上的光标却是白色,那么这个用 CSS 怎么改变呢? 上面描述的情景有两种实现方式 ...

  8. The way get information from mssql by using excel vba and special port

    Yes,  we can get information from mssql by using excel vba.  But the default port of MSSQL is  1433. ...

  9. 2020年digitalocean最新优惠码100美元奖励

    欧美免备案vps服务器digitalocean我用了四年,创建一台vps速度非常快. 由于中国用户扎堆购买Vultr和Linode线路,导致digitalocean中国用户少,反而更稳定.digita ...

  10. java实现邮箱发送邮件

    第一步:封装发件人账号密码 import javax.mail.Authenticator;import javax.mail.PasswordAuthentication; /** * 发件人账号密 ...