题目链接: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. 【Android Studio】查看源码时提示“throw new RuntimeException("Stub!")”

    如题-- 详细问题及解决方法: http://blog.csdn.net/u010917495/article/details/51234179

  2. Downgrade extraction on phones running Android 7/8/9

    Now it's more and more difficult for forensic tools to extract evidence from smartphone running Andr ...

  3. 你了解HTTPS,但你可能不了解X.509

    世上根本就没有HTTPS协议,只有HTTP协议.——知乎某答友 某天,收到领导指示:学习一下X.509相关原理. 很多开发者可能和我一样觉得X.509这个词很陌生,但其实我们经常和它打交道,属于典型的 ...

  4. HTML5 第二章 列表和表格和媒体元素

    列表: (1)什么是列表? 列表就是信息资源的一种展示形式. (2)无序列表: 语法: <ul> <li>第1项</li> <li>第2项</li ...

  5. WPF:事件委托对于不同界面间通信的应用

    界面1内设定点击事件,生成Path用事件传出public partial class TemplateWindow : Window     {         internal delegate v ...

  6. 当下最流行的微服务与spring cloud,你搞清楚了吗?

    微服务架构:Spring-Cloud 什么是微服务? 微服务就是把原本臃肿的一个项目的所有模块拆分开来并做到互相没有关联,甚至可以不使用同一个数据库. 比 如:项目里面有User模块和Power模块, ...

  7. JavaFX 集成 Sqlite 和 Hibernate 开发爬虫应用

    目录 [隐藏] 0.1 前言: 0.2 界面 0.3 Maven 环境 0.4 项目结构 0.5 整合 Hibernate 0.5.1 SQLiteDialect.java 数据库方言代码 0.5.2 ...

  8. SpringMVC学习笔记之---数据绑定

    SpringMVC数据绑定 一.基础配置 (1)pom.xml <dependencies> <dependency> <groupId>junit</gro ...

  9. jmeter使用JDBC连接数据库

    jmeter使用JDBC的配置元件连接数据库,通过sql语句查询需用到的数据 配置元件名称:JDBC connection configuration,使用前,需导入mysql-connector-j ...

  10. PCA(主成分分析)原理,步骤详解以及应用

    主成分分析(PCA, Principal Component Analysis) 一个非监督的机器学习算法 主要用于数据的降维处理 通过降维,可以发现更便于人类理解的特征 其他应用:数据可视化,去噪等 ...