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

题解:一道简单的构造题,一般构造题差不多都考自己脑补,脑洞一开就过了

由于数据x只有1e5,但是要求是1e6,而且我们知道3个数可以组合成任意数也就是说n-3的数从1~1e5直接任意找然后使得其总xor为sum

当sum=x时(定义Max=1<<17 > 1e5)那么这三个数只要组成0就行,当sum!=x时那么这三个数只要构成sum^x就行,这3个数从1e5~1e6中找

很好找的。

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std; int main() {
int n , x;
cin >> n >> x;
if(n == ) {
cout << "YES" << endl;
cout << x << endl;
}
else if(n == ) {
if(x == ) {
cout << "NO" << endl;
}
else {
cout << "YES" << endl;
cout << << ' ' << x << endl;
}
}
else {
int Max = << ;
int sum = ;
cout << "YES" << endl;
for(int i = ; i <= n - ; i++) {
cout << i << ' ';
sum ^= i;
}
if(sum == x) {
cout << Max << ' ' << (Max << ) << ' ' << (Max ^ (Max << )) << endl;
}
else {
cout << << ' ' << (Max ^ sum) << ' ' << (Max ^ x) << endl;
}
}
return ;
}

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

  1. 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 ...

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

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

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

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

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

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

  5. Coderfroces 862 B . Mahmoud and Ehab and the bipartiteness

     Mahmoud and Ehab and the bipartiteness Mahmoud and Ehab continue their adventures! As everybody in ...

  6. codeforces 862B B. Mahmoud and Ehab and the bipartiteness

    http://codeforces.com/problemset/problem/862/B 题意: 给出一个有n个点的二分图和n-1条边,问现在最多可以添加多少条边使得这个图中不存在自环,重边,并且 ...

  7. Codeforces 959 D Mahmoud and Ehab and another array construction task

    Discription Mahmoud has an array a consisting of n integers. He asked Ehab to find another arrayb of ...

  8. Codeforces 959 E Mahmoud and Ehab and the xor-MST

    Discription Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him ...

  9. 【构造】【分类讨论】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, ...

随机推荐

  1. poj 1068 模拟

    题目链接 大概题意就是告诉你有个n个小括号,每一个")"左边有多少个"("都告诉你了,然后让你求出每一对括号之间有多少对括号(包含自己本身). 思路: 我先计算 ...

  2. 基于python的Elasticsearch索引的建立和数据的上传

    这是我的第一篇博客,还请大家多多指点 Thanks ♪(・ω・)ノ         今天我想讲一讲关于Elasticsearch的索引建立,当然提前是你已经安装部署好Elasticsearch. ok ...

  3. oracle-11g2下载安装笔记

    一.下载链接地址 http://download.oracle.com/otn/nt/oracle11g/112010/win64_11gR2_database_1of2.zip http://dow ...

  4. 自定义 Button 选择器

    极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...

  5. Computing Jobs

    docker&k8shadoopsparkhbasemesosrediskafkazookeeper SCSI.NVMe.PCIe devops

  6. mongoDB的CRUD的总结

    今天开始接触非关系型数据库的mongoDB,现在将自己做的笔记发出来,供大家参考,也便于自己以后忘记了可以查看. 首先,mongoDB,是一种数据库,但是又区别与mysql,sqlserver.orc ...

  7. Rootkit与后门隐藏技术

    目录 简介 linux虚拟文件系统VFS rootkit的功能 隐藏文件 基本方法 高级方法 系统调用流程 hook sys_getdents sys_getdents的调用树 最底层的方法 隐藏进程 ...

  8. Yii2 基础模板前后台登录分离

    1.用GII 生成一个模块(modules)名字为 admin 2.在./config/web.php 中加入如下配置 'modules' => [ 'admin' => [ 'class ...

  9. centos7 环境下安装nginx--Linux

    一.安装前需要的编译环境准备 1.安装make yum install -y gcc automake autoconf libtool make 2.安装gcc.gcc-c++ yum instal ...

  10. 基于ZooKeeper的三种分布式锁实现

    [欢迎关注公众号:程序猿讲故事 (codestory),及时接收最新文章] 今天介绍基于ZooKeeper的分布式锁的简单实现,包括阻塞锁和非阻塞锁.同时增加了网上很少介绍的基于节点的非阻塞锁实现,主 ...