Codeforces 862C - Mahmoud and Ehab and the xor
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的更多相关文章
- CodeForces - 862C Mahmoud and Ehab and the xor(构造)【异或】
<题目链接> 题目大意: 给出n.m,现在需要你输出任意n个不相同的数(n,m<1e5),使他们的异或结果为m,如果不存在n个不相同的数异或结果为m,则输出"NO" ...
- CodeForces - 862C Mahmoud and Ehab and the xor(构造)
题意:要求构造一个n个数的序列,要求n个数互不相同,且异或结果为x. 分析: 1.因为0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ (0 ^ 1 ^ 2 ^ 3 ...
- 862C - Mahmoud and Ehab and the xor(构造)
原题链接:http://codeforces.com/contest/862/problem/C 题意:给出n,x,求n个不同的数,使这些数的异或和为x 思路:(官方题解)只有n==2&&am ...
- 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 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)
Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...
- Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)
Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...
- 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 ...
- Codeforces 862B - Mahmoud and Ehab and the bipartiteness
862B - Mahmoud and Ehab and the bipartiteness 思路:先染色,然后找一种颜色dfs遍历每一个点求答案. 代码: #include<bits/stdc+ ...
- Codeforces 862D. Mahmoud and Ehab and the binary string (二分)
题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...
随机推荐
- 剑指offer2
请实现一个函数,将一个字符串中的字符串空格替换成“%20”.例如:“We Are Happy”转化后为“We%20Are%20Happy” 思路:把字符串转化成字符数组,判断这个字符是不是空格,如果是 ...
- vue框架(二)_vue环境搭建及创建项目
1.node.js:概念介绍及安装 node.js:是一个基于chrome浏览器的v8引擎,可以运行javascript的环境(平台) 特性:异步IO模型 npm:是一个包管理器(工具),可以按装依赖 ...
- .apk等常用文件下载出现如果应下载文件,请添加 iis MIME 映射。
在下载.apk文件时出现错误. HTTP 错误 404.3 - Not Found 由于扩展配置问题而无法提供您请求的页面.如果该页面是脚本,请添加处理程序.如果应下载文件,请添加 MIME 映射. ...
- Linux基础命令---lsusb
lsusb 显示本机的usb设备列表,可以显示出usb的详细信息,包括设备的读取速度和描述符.此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE ...
- 获取Linux时间函数
Linux下clock_gettime函数详解 要包含这头文件<time.h> 且在编译链接时需加上 -lrt ;因为在librt中实现了clock_gettime函数. --- stru ...
- 2018 Java线程热门面试题,你知道多少?
面试,难还是不难?取决于面试者的底蕴(气场+技能).心态和认知及沟通技巧.面试其实可以理解为一场聊天和谈判,在这过程中有心理.思想上的碰撞和博弈.其实你只需要搞清楚一个逻辑:“面试官为什么会这样问?他 ...
- 学写网页 #05# CSS Mastery 笔记 1~3
看到第四章才发现这本书已经太旧了..看到第 3 章为止吧.前三章主要讲的内容:一些编码常识.怎样选择元素.盒子模型(主要是 Margin).定位(绝对.相对.浮动.fixed 等) 第一章 conve ...
- P2414 [NOI2011]阿狸的打字机
P2414 [NOI2011]阿狸的打字机 AC自动机+树状数组 优质题解 <------题目分析 先AC自动机搞出Trie图 然后根据fail指针建一只新树 把树映射(拍扁)到一个序列上,用树 ...
- linux内核分析 第四周
一.系统调用的三层皮 内核态.用户态 Intel x86 CPU有四个权限分级,0-3.Linux只取两种,0是内核态,3是用户态. 0xc0000000以上的空间只能在内核态下访问 0x000000 ...
- bzoj 3505 数三角形 - 组合数学
给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形. 注意三角形的三点不能共线. Input 输入一行,包含两个空格分隔的正整数m和n. Output 输出 ...