CF 862C Mahmoud and Ehab and the xor 构造
来源:互联网 发布:数据库关系模式的定义 编辑:程序博客网 时间:2024/05/23 18:08
题意:构造出n个不同的数字a[i](a[i]<=1e6) 要求这n个数字的异或和正好为x. (n,x<=1e5.)
若y==x 则剩下三个为pw,pw*2,pw^(pw*2).
若有解 输出任意一个可行解.
当n==2 x==0时 显然只能为两个相同的数 此时无解,否则一定有解.
构造:n<=1e5,令pw=2^17先输出前n-3个数字1,2...n-3. 令这部分异或和为y若y==x 则剩下三个为pw,pw*2,pw^(pw*2).
若y!=x 则剩下为0,pw,(pw^x^y) (当y==x时 会出现两个pw,pw).
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N=2e5+20;int n,x;int main(){while(cin>>n>>x){if(n==2&&x==0){printf("NO\n");continue;}puts("YES");int y=0,pw=1<<17;for(int i=1;i<=n-3;i++)y^=i,printf("%d ",i);int res=y;if(n==1)printf("%d\n",x);if(n==2)printf("0 %d\n",x);if(n>=3){if(y==x)printf("%d %d %d\n",pw,pw*2,pw+(pw*2));//res=res^pw^(pw*2)^((pw*2)^pw);elseprintf("0 %d %d\n",pw,(pw^x^y));//res=res^pw^(pw^x^y);}//printf("%d\n",res);}return 0;}
阅读全文
0 0
- CF 862C Mahmoud and Ehab and the xor 构造
- codeforce 862C Mahmoud and Ehab and the xor(构造)
- cf 862C Mahmoud and Ehab and the xor 思维+构造
- CF C. Mahmoud and Ehab and the xor
- 862C C. Mahmoud and Ehab and the xor XOR操作/构造
- 862C C. Mahmoud and Ehab and the xor XOR操作/构造
- CF 862 C. Mahmoud and Ehab and the xor【异或】
- Codeforces 862C. Mahmoud and Ehab and the xor
- Codeforces 862C Mahmoud and Ehab and the xor
- Codeforces862C. Mahmoud and Ehab and the xor 【构造】
- Mahmoud and Ehab and the xor CodeForces
- Mahmoud and Ehab and the xor CodeForces
- Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)
- CF 862A. Mahmoud and Ehab and the MEX
- Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor(xor运算应用)
- Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor
- Codeforces Round #435 (Div. 2): C. Mahmoud and Ehab and the xor
- Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor
- php正则表达式手册
- java的varargs机制
- 【转】【DBSDFZOJ 1163】分治 第K小元素(分治)
- [eclipse]1.创建dynamic web project总是不行
- Xargs用法详解(原创)
- CF 862C Mahmoud and Ehab and the xor 构造
- leetcode 188. Best Time to Buy and Sell Stock IV 最大子段和
- 数据库 inner join,right join,left join ,以及其后的and ,where 条件
- JAVA高级试题
- PYTHONPATH environment variable
- android 圆角边框 textview
- 静态方法
- unity 优化方案
- 么是github