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次),每次提问提出一个字符串,会返回这 ...
随机推荐
- JSP—内置对象
JSP内置对象是Web容器创建的一组对象,不用声明,直接使用 out 输出对象 类型 javax.servlet.jsp.JspWriter 作用域 Page request 请求对象 类型 java ...
- linux安装composer及安装yii2
wget https://getcomposer.org/download/1.3.2/composer.phar mv composer.phar /usr/local/bin/composer c ...
- Keepalived 安装
Keepalived 安装安装环境 keepalived-1.2.18.tar.gz VM虚拟机redhat6.5-x64:192.168.1.201 Xshell4 部署方案 201部署 安装步骤 ...
- 实现kylin定时跑当天的任务
说明: 每天自动构建cube,动态在superset里面查看每天曲线变化图 #! /bin/bash ##cubeName cube的名称 ##endTime 执行build cube的结束时间 (命 ...
- linux常用命令:whereis 命令
whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b).man说明文件(参数-m)和源代码文件(参数-s).如果省略参数,则返回所有信息. 和find相比,whereis查找的速度非 ...
- python webdriver 登陆163邮箱给QQ邮箱发送一个邮件,显示等待
#encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webdriver i ...
- 彻底明白Flink系统学习5:window、Linux本地安装Flink
http://www.aboutyun.com/thread-26393-1-1.html 问题导读 1.如何在window下安装Flink? 2.Flink本地安装启动命令与原先版本有什么区别? 3 ...
- P4391 [BOI2009]Radio Transmission 无线传输
P4391 [BOI2009]Radio Transmission 无线传输 kmp 题目让我们求一个串的最小循环子串 我们回想一下kmp中的失配函数 用 f 数组保存当前字符匹配失败后,需要跳到的前 ...
- Python3 Selenium定位不到元素常见原因及解决办法
Python3 Selenium定位不到元素常见原因及解决办法 一.问题描述 在做web应用的自动化测试时,定位元素是必不可少的,这个过程经常会碰到定位不到元素的情况: 报错信息: no such e ...
- python的回收机制
1,我们为什么要启用变量 因为我也不确定用户扔给我的数据是什么,有些同学在写程序的时候就已经将变量限定死了,我就说你这样不好,你只想测试一次吗,如果你想确保你的程序万无一失,通俗点说的话,就是“抗揍” ...