原题链接: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. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_10 打印流_1_打印流_概述和使用

    system.out就是打印流 System的源码里面out参数就是一个PrintStream类型的 例如路径写的是E盘,.没有e盘这个路径就会抛出异常 用println直接写入的就是97    这个 ...

  2. #1146 - Table 'phpmyadmin.pma__table_uiprefs' doesn't exist

    在使用phpmyadmin时,数据库总报错#1146 - Table ‘phpmyadmin.pma_table_uiprefs' doesn't exist 修改phpmyadmin的配置文件con ...

  3. JS使用 popstate 事件监听物理返回键

    pushHistory();        window.addEventListener("popstate", function (e) {            if (or ...

  4. docker搭建一个渗透测试环境 bwapp为例

    bwapp是一个渗透测试靶场,他其中中含有100多个Web漏洞  基本涵盖了所有主要的已知Web漏洞,包括OWASP Top 10的各种 首先要去搜索一下  看一下有哪些镜像可以下载    docke ...

  5. python基础-6 正则表达式

    一 python正则简介 就其本质而言,正则表达式(或 RE)是一种小型的.高度专业化的编程语言,(在Python中)它内嵌在Python中,并通过 re 模块实现. 正则表达式模式被编译成一系列的字 ...

  6. web 前端1 html5基础

    HTML web sockent 实例 import socket def handle_request(client): buf = client.recv(1024) client.sendall ...

  7. 第五周总结&第三次实验报告

    实验三 String类的应用 实验目的 掌握类String类的使用: 学会使用JDK帮助文档: 实验内容 1.已知字符串:"this is a test of java".按要求执 ...

  8. mybatis如何把session托管给spring

    原生mybatis创建SqlSession的流程: SqlSession sqlSession = null; try { sqlSession = sqlSessionFactory.openSes ...

  9. 下载JSON数据

    最近学习MongoDB,需要获取大量Json在线数据,例如: http://media.mongodb.org/zips.json 此处使用c#,直接给出代码: HttpWebRequest requ ...

  10. Java-集合第六篇操作集合的工具类Collections

    1.Java提供了一个操作Set.List.Map等集合的工具类:Collections. 工具类中提供的方法主要针对Set.List.Map的排序.查询.修改等操作,以及将集合对象设置为不可变.对集 ...