原题链接: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. Powershell指令集_1

    目录 目录 前言 程序进度条 Write-Progress 执行表达式 Invoke-Expression 表格化打印信息 Format-Table 获取系统服务 Get-WmiObject 循环 F ...

  2. Delphi XE2 之 FireMonkey 入门(2)

    FireMonkey 的控件都是自己绘制的(而不是基于系统组件), 我想它们应该是基于一些基本图形; 就从基本图形开始吧. FMX.Objects 单元给出的类: TShape //基本图形的基类 T ...

  3. Jmeter之CSV Data Set Config

    在很多情况下,需要针对测试数据做参数化操作,Jmeter提供了很好用的CSV Data Set Config插件. 一.界面显示 二.界面说明 1.名称:标识,建议设置为该组件是提供什么功能 2.注释 ...

  4. Caffe深度学习计算框架

    Caffe | Deep Learning Framework是一个清晰而高效的深度学习框架,其作者是博士毕业于UC Berkeley的 Yangqing Jia,目前在Google工作.Caffe是 ...

  5. Vue路由注意事项

    一.vue中路由的使用 1.定义组件 <template> <div class="hello"> <h1 @click="info&quo ...

  6. 接口框架 python+unittest+request+HTMLTestRunner

    request的各种方法主要用来处理客户端浏览器提交的请求中的各项参数和选项.如POST,GET最常用的两种请求 官方文档:http://docs.python-requests.org/en/mas ...

  7. Linq查询语法(1)

    转:http://www.cnblogs.com/ahao214/archive/2013/01/22/2871044.html LINQ的基本格式如下所示:var <变量> = from ...

  8. Console.Out 属性和 XmlDocument.Save 方法 (String)

    Console.Out 属性 默认情况下,此属性设置为标准输出流. 此属性可以设置为另一个流SetOut方法. 请注意,调用Console.Out.WriteLine方法是等效于调用相应WriteLi ...

  9. 在使用spring中的ContextConfiguration、test注解时出现的错误

    错误: 在使用测试注解时出现ContextConfiguration注解和test注解无法正常导包使用的编译异常,如图: 解决办法: 将pom.xml文件中以下依赖管理 中的<scope> ...

  10. [Python3] 005 列表的基本使用

    目录 1. 列表概述 2. 创建列表 3. 列表常用操作 (1) 访问列表 (2) 分片操作 1) 正向操作 2) 反向操作 3) 内置函数 id() 加入队伍 1. 列表概述 一组有顺序的数据的组合 ...