Codeforces Round #435 (Div. 2)-异或规律&思维-Mahmoud and Ehab and the xor
来源:互联网 发布:三唑仑淘宝上输什么 编辑:程序博客网 时间:2024/06/05 15:14
http://codeforces.com/contest/862/problem/C
给定一个数m,要求你输出n个数,这n个数异或的结果是m
开始的思路是 让m和 1-n都异或。燃火把1-n+1都标记为true
然后把 结果vis[sum] 变成false.
但是如果 sum不在 1-n+1中就坑了。。。
我又想出了 输出1——n-1,然后把 ans(1-n-1的疑惑和)^x^m 和x输出。
关键是这俩数不能相等,不然GG。。
然后就看题解了。。
发现 结果要求和给的数有一个差值。
输入的n肯定是1e5.而结果可以是1e6
于是就 特判了 后面三个数,保证了后面三个绝对不会相同。。
#include <bits/stdc++.h>using namespace std;const int maxn=1e5+100;bool vis[maxn];int main(){ int m,n; while(~scanf("%d%d",&m,&n)){ int sum=n; memset(vis,false,sizeof(vis)); for(int i=1;i<=m;i++){ sum=sum^i; vis[i]=true; } if(m==1){ printf("YES\n"); printf("%d",n); } else if(m==2){ if(n==0) puts("NO"); else{ puts("YES"); printf("0 %d\n",n); } } else{ puts("YES"); int x=1<<17; int y=1<<18; int sum=0; for(int i=1;i<=m-3;i++){ printf("%d ",i); sum^=i; } printf("%d %d %d\n",x,y,x^y^sum^n); } } return 0;}
阅读全文
0 0
- Codeforces Round #435 (Div. 2)-异或规律&思维-Mahmoud and Ehab and the xor
- Codeforces Round #435 (Div. 2)-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 【位运算+思维】
- 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
- 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
- Mahmoud and Ehab and the xor CodeForces
- Mahmoud and Ehab and the xor CodeForces
- Codeforces Round #435 (Div. 2) 之Mahmoud and Ehab and the MEX
- Codeforces Round #435 (Div. 2) A. Mahmoud and Ehab and the MEX(思路)
- Codeforces Round #435 (Div. 2)-B. Mahmoud and Ehab and the bipartiteness
- Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string
- Codeforces Round #435 (Div. 2) E. Mahmoud and Ehab and the function
- Android-Java 小知识点整理
- Maven 常见问题解决
- java基础知识总结1
- 推荐一些非常有用的博客
- 自己做身份证社保等回执
- Codeforces Round #435 (Div. 2)-异或规律&思维-Mahmoud and Ehab and the xor
- C++输入正整数,输出1-n*n顺时针排列矩阵之动态分配
- 装修领域的信息化
- 安装arcgis10.5不能启动服务的解决方案
- 在windows上安装git
- String类常用的方法
- Mongodb学习笔记 --- Mongodb使用步骤
- Robust Real-Time Extreme Head Pose Estimation
- MatchExpression(2):实现