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. ACM 未解决的问题

    还没有搞定的ACM问题列表. google code jam Round1A Round1B Round1C Round2 Round3 Onsite Finals 百度之星 一.资格赛题目: dis ...

  2. mysql的count方法详解

    1.cout(*)会统计为null的行: 2.count(列名)不会统计此列null值的行: 3.count(distinct col)计算该列除null之外的不重复数量:

  3. JSON语法2

    把 JSON 文本转换为 JavaScript 对象 JSON 最常见的用法之一,是从 web 服务器上读取 JSON 数据(作为文件或作为 HttpRequest),将 JSON 数据转换为 Jav ...

  4. 优化 MySQL: 3 个简单的小调整

    我并不期望成为一个专家级的 DBA,但是,在我优化 MySQL 时,我推崇 80/20 原则,明确说就是通过简单的调整一些配置,你可以压榨出高达 80% 的性能提升.尤其是在服务器资源越来越便宜的当下 ...

  5. POJO/VO/DTO等对象模型

    JavaBean 要想成为JavaBean,需要满足以下条件: 1,提供一个默认的无参构造函数. 2,需要被序列化并且实现了Serializable接口. 3,可能有一系列可读写属性伴随"g ...

  6. 动态规划(Dynamic Programming)

    introduction 大部分书籍介绍"动态规划"时,都会从"菲波纳切数列"讲起. 菲波纳切数列 递归解法 C++ 代码如下 unsigned long in ...

  7. 20145310《网络对抗》Exp2 后门原理与实践

    实验内容 (1)使用netcat获取主机操作Shell,cron启动,使用socat获取主机操作Shell, 任务计划启动. (2)使用MSF meterpreter生成可执行文件,利用ncat或so ...

  8. jz2440移植QT5.6【学习笔记】【原创】

    平台:jz2440 作者:庄泽彬(欢迎转载,请注明作者) 交叉编译工具:arm-linux-gcc (GCC)4.4.3 linux:linu3.4.2 PC环境:ubuntu18.04 一.修改/o ...

  9. tslib移植笔记(1)【转】

    本文转载自:https://blog.csdn.net/zijie_xiao/article/details/50740950 tslib移植笔记(1)2016-04-25 tslib背景[摘自百度] ...

  10. 风景区的面积及道路状况分析问题 test

    参考文献:   https://wenku.baidu.com/view/b6aed86baf1ffc4ffe47ac92.html #include <bits/stdc++.h> us ...