原题链接: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. JSPDF 原理

    Jspdf是一个将html内容生成pdf文件的库,原理是对输入浏览器的文字或二进制图片进行base64编码转换,以pdf中应有的形式组织,最终以data uri scheme, data:applic ...

  2. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_08 转换流_3_转换流的原理

    FileReader源码的构造方法.底层使用FileInputStram读取 编码不一样占用的字节大小也不一样.GBK一个汉字占用 2个字节. utf-8一个汉字占用三个字节 转换流InputStre ...

  3. 《图解设计模式》读书笔记7-1 facade模式

    目录 1. Facade模式简介 2. 示例程序 2.1 类图 2.2 程序 3.角色和类图 4.思路拓展 1. Facade模式简介 开发程序的过程中,随着时间的推移,类会越来越多,调用关系会越来越 ...

  4. Delphi 遍历类中的属性

    http://blog.csdn.net/easyboot/article/details/8004954 Delphi 遍历类中的属性 标签: delphistringbuttonclassform ...

  5. 转:高效实用的.NET开源项目

    本文转自:http://www.cnblogs.com/pengze0902/p/7669631.html 似乎...很久很久没有写博客了,一直都想写两篇,但是却没有时间写.感觉最近有很多事情需要处理 ...

  6. Nginx基本属性配置

    Nginx基本属性配置 1.找到安装目录下conf 文件下的nginx.conf文件 通过 Notepad++打开进行 属性配置   image ==>   image 2.worker_pro ...

  7. 阿里云SLB产品HTTP、HTTPS、UDP协议使用

    1.http协议测试 第一步:添加http监听服务,前端端口为8080,后端端口为80,健康检查中检查端口为后端端口80: 第二步:在绑定的服务器上安装服务,步骤如下 centos系统中启动http协 ...

  8. java8 语言特性

    Lamda 表达式 使用内部类也可以实现相关的功能, 但使用lamda更简短 lamda 的参数类型可以省略 如果是单条语句, lamda 的花括号可以省略 如果是单条语句, lamda 的 retu ...

  9. Python3的基本数据类型

    2.1. Python3中六个标准的基本数据类型: Number(数字) String(字符串) Sets(集合) Tuple(元组) List(列表) Dictionary(字典) 2.2. Pyt ...

  10. iptables防火墙常用命令

    iptables防火墙启动停止和基本操作 iptables是centos7之前常用的防火墙,在centos7上使用了firewall 防火墙基本操作: # 查询防火墙状态 service iptabl ...