862C - Mahmoud and Ehab and the xor

思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了,0异或x等于x。所以只要把剩下的异或起来变成x就可以了。如果剩下来有3个,那么,这3个数可以是x^i^j,i,j。

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=1e7+;
bool vis[N]={false};
bool vs[]={false};
vector<int>ans;
vector<int>temp;
int n,x;
bool flag=false;
void dfs(int s,int t,int n)
{
if(flag)return ;
if(t==)
{
if(!vs[n])
{
for(int i=;i<temp.size();i++)
ans.pb(temp[i]),vis[temp[i]]=true;
ans.pb(n),vis[n]=true;
flag=true;
}
return ;
}
for(int i=s;i<;i++)
{
temp.pb(i);
vs[i]=true;
if(i!=x)dfs(i+,t-,n^i);
vs[i]=false;
temp.pop_back();
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n,x;
cin>>n>>x;
if(n==&&x==)
{
cout<<"NO"<<endl;
return ;
}
int t=n%,t1=n-t;
if(t==&&n!=)t=,t1-=;
if(t==)t=,t1-=;
vis[x]=true;
dfs(,t-,x);
for(int i=;i<(<<);i++)
{
if(t1)
{
if((!vis[i])&&(!vis[-i]))
{
ans.pb(i);
ans.pb(-i);
vis[i]=vis[-i]=true;
t1-=;
}
}
else break;
}
cout<<"YES"<<endl;
for(int i=;i<ans.size();i++)
{
cout<<ans[i];
if(i!=ans.size())cout<<' ';
}
cout<<endl;
return ;
}

Codeforces 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(构造)

    题意:要求构造一个n个数的序列,要求n个数互不相同,且异或结果为x. 分析: 1.因为0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ (0 ^ 1 ^ 2 ^ 3 ...

  3. 862C - Mahmoud and Ehab and the xor(构造)

    原题链接:http://codeforces.com/contest/862/problem/C 题意:给出n,x,求n个不同的数,使这些数的异或和为x 思路:(官方题解)只有n==2&&am ...

  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 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  6. Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)

    Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...

  7. Codeforces 862A Mahmoud and Ehab and the MEX

    传送门:CF-862A A. Mahmoud and Ehab and the MEX time limit per test 2 seconds memory limit per test 256 ...

  8. Codeforces 862B - Mahmoud and Ehab and the bipartiteness

    862B - Mahmoud and Ehab and the bipartiteness 思路:先染色,然后找一种颜色dfs遍历每一个点求答案. 代码: #include<bits/stdc+ ...

  9. Codeforces 862D. Mahmoud and Ehab and the binary string (二分)

    题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...

随机推荐

  1. PIMPL(一)

    1 参考 <effective C++> 条款31:将文件间的编译关系降至最低 PIMPL Idiom: http://c2.com/cgi/wiki?PimplIdiom 2 什么是PI ...

  2. checkBox的使用和事件监听

    直接上代码: <!DOCTYPE html> <html> <head> <title></title> </head> < ...

  3. VMWARE安装centos6 http://www.centoscn.com/image-text/setup/2013/0816/1263.html

    http://www.centoscn.com/image-text/setup/2013/0816/1263.html

  4. Webform和MVC,为什么MVC更好一些?(转)

    转自http://www.admin10000.com/document/5277.html 前言 如果你看了最近微软的议程,你会发现他们现在的焦点除了MVC,还是MVC.问题在于为什么微软如此热衷于 ...

  5. java tar.gz文件生成

    /** * 压缩文件成Gzip格式,Linux上可使用 * 压缩文件夹生成后缀名为".gz"的文件并下载 * @param folderPath,要压缩的文件夹的路径 * @par ...

  6. python chunk模块

    chunk模块用于读取TIFF格式的文件,打开应该使用二进制模式 TIFF 标签图像文件格式 import chunk import chunk f=open('E:\\test.tiff','rb' ...

  7. MyBatis学习笔记(六)——调用存储过程

    转自孤傲苍狼的博客:http://www.cnblogs.com/xdp-gacl/p/4270352.html 一.提出需求 查询得到男性或女性的数量, 如果传入的是0就女性否则是男性 二.准备数据 ...

  8. mysql创建外链失败1005错误解决方法

    mysql创建外链失败1005错误解决方法 错误号:1005错误信息:Can't create table 'webDB.#sql-397_61df' (errno: 150)解决方法 错误原因有四: ...

  9. (mac)阿里云ECS服务器配置过程

    -----首先本人是半只脚入门的iOS开发者,弄这个只是单纯想多学点东西. -----阿里云服务器的配置选择:既然是学习用的,最最基础的配置就行了.1M带宽,1核1G...这就不详述了.没啥可选的,( ...

  10. P2260 [清华集训2012]模积和

    P2260 [清华集训2012]模积和 整除分块+逆元 详细题解移步P2260题解板块 式子可以拆开分别求解,具体见题解 这里主要讲的是整除分块(数论分块)和mod不为素数时如何求逆元 整除分块:求Σ ...