<题目链接>

题目大意:

给出n、m,现在需要你输出任意n个不相同的数(n,m<1e5),使他们的异或结果为m,如果不存在n个不相同的数异或结果为m,则输出"NO",本题中所有数均需小于1e6。

解题分析:
因为本题是SPJ,且当n比较大的时候,需要输出很多数,所以我们试着去构造这n个数,力图找出一些规律。n<=2的时候很好直接进行特判即可。n>=3的时候,可以直接进行简单的构造,比如前面n-1项依次设为1,2,3,……(下面假设前面这些连续的项异或结果为res),最后一项为  cur = res^m (这是根据 0^x = x ,这个公式得到的,即前面的所有项都进行简单构造,然后最后一项让这n个数的异或结果为m)。这样看上去很完美,实际上存在一些漏洞。因为题目要求这n个数必须不相同,但是按照上面的构造方法,是可能让cur与前面n-1个数相同的,不相信的同学可以简单构造反例,所以,我们需要引进两个大的二进制数来避免这种情况,因为按照我们前面的够着方法,前n-1个数最大会小于n,而n<1e5,但是题目对我们构造的数的范围要求要小于1e6,所以我们可以添加两个大于1e5,小于1e6的数,同时,尽量让这两个数与之前构造的n-3个数之间相互异或的结果都不能为0 (至于为什么是要两个这样的数,可以自行举反例,主要的判断冲突依据就是这n个数必须互不相同)。所以最后的一个数cur = res^x1^x2^m。

#include <iostream>
using namespace std; int main(){
ios::sync_with_stdio(false);
int n,m;cin>>n>>m;
if(n==){
puts("YES");
cout<<m<<endl;
}else if(n==){
if(!m) {
puts("NO");
}else {
puts("YES");
cout<<"0 "<<m<<endl;
}
}else{
int x1=<<,x2=<<;
puts("YES");
int res=;
for(int i=;i<=n-;i++){
cout<<i<<" ";
res^=i;
}
cout<<x1<<" "<<x2<<" "<<(res^x1^x2^m) <<endl;
}
}

2019-02-01

CodeForces - 862C Mahmoud and Ehab and the xor(构造)【异或】的更多相关文章

  1. Codeforces 862C - Mahmoud and Ehab and the xor

    862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了 ...

  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. swift 实践- 09 -- UIImageVIew

    import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...

  2. JS实现图片放大查看

    示例:https://wumaozheng.com/static-pages/image-magnifier.html <!DOCTYPE html> <html> <h ...

  3. Confluence 6 Windows 中以服务方式自动重启为服务手动安装 Confluence 分发包

    在 Windows: 打开一个命令输入框,然后修改目录到 <CONFLUENCE-INSTALL>/bin 目录中.你需要以管理员权限运行这个命令行输入框(Run as administr ...

  4. ionic3 启动白屏处理

    重点就就三点 1.设置不自动隐藏splashscreen页面,设置最多延迟10s再关闭,这样可以不显示启动前的白画面 <preference name="AutoHideSplashS ...

  5. 解决Xshell不从22端口连接服务器

    xshell默认是22端口 如果服务器给的ssh端口不是22,会连接失败 需要去指定连接 新建 设置ip和端口,点下面的确定 双击刚创建的会话 输入用户名密码 连接成功

  6. Android学习基础部分

    今天是放寒假的第四天,这几天加上放假前总共弄了一些Android编程的基础部分,比如下载sdk.配置环境.下载Eclipse的插件(ADT).下载Android Studio.VirtualBox.G ...

  7. Altium Designer (17.0) 打印输出指定的层

    Altium Designer (17.0) 例如,打印输出Top Overlay,Keep-Out Layer 1.先选择PCB文件,在单击按键Print Preview... 2.在预览区单击鼠标 ...

  8. C++ shut down a computer

    前阵子有朋友问我,怎么用C语言写一个小程序,控制电脑关机.这个我真的不懂,这几天闲着,就上网搜了搜,整理一下. IDE: Code::Blocks 16.01 操作系统:Windows 7 x64 # ...

  9. nginx+tomcat实现集群,redis实现session共享,软连接实现文件共享:http://blog.csdn.net/hua1586981/article/details/78132710

    转载 2017年02月08日 16:52:41 730 相信很多人都听过nginx,这个小巧的东西慢慢地在吞食apache和IIS的份额.那究竟它有什么作用呢?可能很多人未必了解. 说到反向代理,可能 ...

  10. 如何在EXCEL中找出第一列中不包含的第二列数据

    1.找出第一列中不包含的第二列数据:=IFERROR(VLOOKUP(A:A,B:B,1,0),"无") 2.A列相同,B列相加:=SUMIF(G:G,G1,J:J)