原题链接:http://codeforces.com/contest/862/problem/C

题意:给出n,x,求n个不同的数,使这些数的异或和为x

思路:(官方题解)只有n==2&&x==0时输出NO,接下来考虑YES的情况

先定义一个数pw=217(输出答案时保证不会出现重复数字)

因为 数x 完全可以由三个数异或得到,那么对于n>3的情况,先求1到n-3的异或和,得到y,如果y==x,那么剩下三个数为pw, pw*2, pw^(pw*2)(当x==0时,0, pw,pw^x的输出是不符合题意的),否则输出0, pw,pw^x^y。

n<=3的情况可以直接输出。

AC代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN=1e5+;
const int pw=<<;
int main()
{
int n,x;
scanf("%d %d", &n, &x);
if(n==&&x==)printf("NO\n");
else
{
printf("YES\n");
if(n==) printf("%d\n", x);
else if(n==) printf("%d %d\n", , x);
else if(n==) printf("%d %d %d\n", pw^x, pw<<, pw^(pw<<));
else
{
int res=;
printf("%d", );
for(int i=;i<=n-;i++){
res^=i;
printf(" %d", i);
}
if(res==x){
printf(" %d %d %d\n", pw, pw<<, pw^(pw<<));
}
else {
//cout<<'*'<<endl;
printf(" %d %d %d\n", , pw, pw^x^res);
}
}
}
return ;
}

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. CodeForces - 862C Mahmoud and Ehab and the xor(构造)

    题意:要求构造一个n个数的序列,要求n个数互不相同,且异或结果为x. 分析: 1.因为0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ (0 ^ 1 ^ 2 ^ 3 ...

  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 Round #435 (Div. 2) C. Mahmoud and Ehab and the xor

    题意:给你n,x,均不超过10^5,让你构造一个无重复元素的n个元素的非负整数集合(每个元素不超过10^6),使得它们的Xor和恰好为x. 如果x不为0: 随便在x里面找一个非零位,然后固定该位为0, ...

  6. codeforces 862 C. Mahmoud and Ehab and the xor(构造)

    题目链接:http://codeforces.com/contest/862/problem/C 题解:一道简单的构造题,一般构造题差不多都考自己脑补,脑洞一开就过了 由于数据x只有1e5,但是要求是 ...

  7. 【Codeforces Round #435 (Div. 2) C】Mahmoud and Ehab and the xor

    [链接]h在这里写链接 [题意] 让你组成一个n个数的集合,使得这n个数的异或和为x; x<=1e5 每个数最大1e6; [题解] 1e5<=2^17<=2^18<=1e6的 ...

  8. Codeforces 959 F. Mahmoud and Ehab and yet another xor task

    \(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...

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

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

随机推荐

  1. linux查找所有文件中某个字符串

    查找目录下的所有文件中是否含有某个字符串 find .|xargs grep -ri "IBM" 查找目录下的所有文件中是否含有某个字符串,并且只打印出文件名 find .|xar ...

  2. vue封装element中table组件

    后台系统,table被用的次数比较多,所以决定提出来作为组件 1.新建一个Table.vue文件 <!--region 封装的分页 table--> <template>  & ...

  3. 使用fiddler,提示系统找不到相应的文件FSE2.exe文件

    使用fiddler时候遇到了如下问题: Rules中customize rules 时,提示系统找不到相应的文件FSE2.exe文件. 这个文件的位置可以在Tools->opinions-> ...

  4. IIS下如何配置免费的https

    1.首先我们要取走我们的证书,保存在我们本地的电脑里,然后复制到服务器即可. 2.取走后接下来干嘛?当然是打开文件看看里面有些什么啊.我们找到IIS那个压缩包并解压. 3.解析得到pfx文件,也就是我 ...

  5. 计算距离的SQL语句

    一,BEGINset @num=6378.138*2*ASIN(SQRT(POW(SIN((lat1*PI()/180-lat2*PI()/180)/2),2)+COS(lat1*PI()/180)* ...

  6. “希希敬敬对”队软件工程第九次作业-beta冲刺第一次随笔

    队名:  “希希敬敬对” 龙江腾(队长) 201810775001 杨希                   201810812008 何敬上 201810812004 今日讨论会议照片一张: 每个人 ...

  7. HDU 5945 题解(DP)(单调队列)

    题面: Fxx and game Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) T ...

  8. 两种方法删除ArrayList里反复元素

    方法一: /** List order not maintained **/ public static void removeDuplicate(ArrayList arlList) { HashS ...

  9. 构建CRD工程 - 程序员学点xx 43 k8s

    目录 Kubernetes -3- 这是yann的第98篇分享 本日状态: ​ 帮同事排了一天bug. Kubernetes -3- 这是yann的第98篇分享 第 1 部分 承前 昨天用视屏的方式演 ...

  10. 在vsCode中用git命令合并分支

    提交修改代码到本地仓库 $ git commit -m "修改的东西的描述"切换到master主分支上 $ git checkout master拉取主分支上面的代码 $ git ...