【链接】h在这里写链接


【题意】


让你组成一个n个数的集合,使得这n个数的异或和为x;
x<=1e5
每个数最大1e6;

【题解】


1e5<=2^17<=2^18<=1e6的
/*

    如果n==1;

    输出x就好;

    如果n==2;

        如果x==0,无解。

        如果x!=0,输出一个0,输出一个x.

    如果n==3

        如果x==0,输出(1<<17)|x,(1<<17)|(1<<18),1<<18

        如果x!=0,输出(1<<17)|x,(1<<17)|(1<<18),1<<18

    如果n>3

        设temp = 1^2^...^n-3

        则令n=3,x = x ^ temp

        再做一遍n=3的情况就好

*/


【错的次数】


0

【反思】


下次真的不要再这样了。
总是还没想好,就马上开始写了。
然后写的时候问题重重。

【代码】

#include <bits/stdc++.h>
using namespace std; int n, x,now; void deal(int x) {
cout << ((1 << 17) | x) << ' ' << ((1 << 17) | (1 << 18)) << ' ' << (1 << 18) << endl;
now ^= x;
} int main() {
//freopen("F:\\rush.txt", "r", stdin);
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> x;
if (n == 1) {
cout << "YES" << endl;
cout << x << endl;
return 0;
}
if (n == 2) {
if (x == 0)
return cout << "NO" << endl, 0;
else
return cout << "YES" << endl << "0 " << x << endl, 0;
}
if (n == 3) {
cout << "YES" << endl;
deal(x);
return 0;
}
cout << "YES" << endl;
int temp = 0;
for (int i = 1; i <= n - 3; i++)
temp^=i,cout << i << ' ',now^=i;
deal(x^temp);
return 0;
}

【Codeforces Round #435 (Div. 2) C】Mahmoud and Ehab and the xor的更多相关文章

  1. 【Codeforces Round #435 (Div. 2) A】Mahmoud and Ehab and the MEX

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 让x没有出现,以及0..x-1都出现就可以了. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/std ...

  2. 【Codeforces Round #435 (Div. 2) B】Mahmoud and Ehab and the bipartiteness

    [链接]h在这里写链接 [题意] 让你在一棵树上,加入尽可能多的边. 使得这棵树依然是一张二分图. [题解] 让每个节点的度数,都变成二分图的对方集合中的点的个数就好. [错的次数] 0 [反思] 在 ...

  3. 【Codeforces Round #435 (Div. 2) A B C D】

    CF比赛题目地址:http://codeforces.com/contest/862 A. Mahmoud and Ehab and the MEX ·英文题,述大意:      输入n,x(n,x& ...

  4. 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers

    [链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...

  5. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  6. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  7. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  8. 【Codeforces Round #423 (Div. 2) C】String Reconstruction

    [Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...

  9. 【Codeforces Round #423 (Div. 2) B】Black Square

    [Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...

随机推荐

  1. js函数的解析与执行过程

    function f(a,b,c){ alert(a);//函数字符串 alert(b); var b = 5; function a(){ } } f(1,2); //预处理 lexicalEnvi ...

  2. Laravel输出sql语句

    $queries = DB::getQueryLog();

  3. chkconfig---检查设置系统服务

    chkconfig命令   chkconfig命令检查.设置系统的各种服务.这是Red Hat公司遵循GPL规则所开发的程序,它可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各类常驻服务 ...

  4. 今日题解------codeforces 895C

    题意:给你一个数列,然后找任意数量的数字(除了空集),使得他们的乘机为一个数的平方 我们发现元素最大70,所以我们可以从这里入手,平方数有个性质就是它的所有质因子的指数为偶数 比如:36 = 2*2* ...

  5. Android开发之经常使用开源库直接拿来用

    1.from  代码家 整理比較好的源代码连接 **************************************************************************** ...

  6. LinearLayout-margin不起作用的处理

    1.如果LinearLayout中使用android:layout_marginRight不起作用,通过测试原来在android2.x中,如果一个控件中有android:layout_gravity属 ...

  7. Vue Invalid handler for event "": got undefined

    原因:绑定的方法不是放在methods:{}里.比如我把绑定的函数写在了computed:{}里就会报这个错.

  8. BZOJ1014[JSOI2008]火星人prefix(splay维护hash)

    Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 ...

  9. vmware workstation安装windows server 2019

    提示需要输入密钥,选择[我没有密钥] 选择有桌面体验的 自定义 新建C盘 100G 选择100G的主分区,下一步 PS:未分配的空间,先不理,安装完系统,进桌面,再分配 开始安装.接下来就是等. 等. ...

  10. URL短地址压缩算法 微博短地址原理解析 (Java实现)

    原博客地址:http://blog.csdn.net/xyz_lmn/article/details/8057270 最近,项目中需要用到短网址(ShortUrl)的算法,于是在网上搜索一番,发现有C ...