codeforces 862 C. Mahmoud and Ehab and the xor(构造)
题目链接: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(构造)的更多相关文章
- 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 ...
- CodeForces - 862C Mahmoud and Ehab and the xor(构造)【异或】
<题目链接> 题目大意: 给出n.m,现在需要你输出任意n个不相同的数(n,m<1e5),使他们的异或结果为m,如果不存在n个不相同的数异或结果为m,则输出"NO" ...
- Codeforces 959 F. Mahmoud and Ehab and yet another xor task
\(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...
- Codeforces 862C - Mahmoud and Ehab and the xor
862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了 ...
- Coderfroces 862 B . Mahmoud and Ehab and the bipartiteness
Mahmoud and Ehab and the bipartiteness Mahmoud and Ehab continue their adventures! As everybody in ...
- codeforces 862B B. Mahmoud and Ehab and the bipartiteness
http://codeforces.com/problemset/problem/862/B 题意: 给出一个有n个点的二分图和n-1条边,问现在最多可以添加多少条边使得这个图中不存在自环,重边,并且 ...
- 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 ...
- 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 ...
- 【构造】【分类讨论】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, ...
随机推荐
- openGL基本概念
OpenGL自身是一个巨大的状态机(State Machine):一系列的变量描述OpenGL此刻应当如何运行.OpenGL的状态通常被称为OpenGL上下文(Context).我们通常使用如下途径去 ...
- SWT 注意事项
一:GridData (1) 将 GridData 的 widthHint 设置为0,可以解决控件大小会随着这其默认值长度大小而改变的问题.
- 拉格朗日对偶性(Lagrange duality)
目录 拉格朗日对偶性(Lagrange duality) 1. 从原始问题到对偶问题 2. 弱对偶与强对偶 3. KKT条件 Reference: 拉格朗日对偶性(Lagrange duality) ...
- ajax具体实现学习记录
记录自己对ajax\的理解, 首先要明白ajax是为了解决什么问题,简单来讲就是为了局部刷新页面,而不刷新整个界面.就比如现在有一个实时热度的显示,它是不断变化的,所以你肯定要不停的从数据库当中获取热 ...
- zookeeper 集群配置
安装前要先确保配置好 jdk,这里不在讲述 一. 将zookeeper 安装包下载到你想要的目录 下载地址:http://mirrors.hust.edu.cn/apache/zookeeper/ m ...
- centos开发环境安装
执行 yum install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel ...
- A solution to the never shortened to-do list
I once told my younger sister my learning system, and the basic five doctrines of my methodology. Bu ...
- Java——检测其他线程的状态以及启动已死亡的线程
这次这个的思路是在主类中维护一个map,map的key是线程名,value是线程的状态,然后创建周期执行的线程通过检测这个map来判断进程的状态,如果有死亡的进程就把该进程启动. 首先是主类,这里的m ...
- Hive安装与部署
进去root权限(su) 1.从https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-1.2.2/apache-hive-1.2.2-bin.ta ...
- Python 面向導向語言 Object Oriented Programming Language
Pytho 是面向對象的程式語言,舉凡 Literals 值都是 Object.例如: >>> id(38)8791423739696 與 >>> id('ABC' ...