862C C. Mahmoud and Ehab and the xor XOR操作/构造
来源:互联网 发布:沙发品牌 知乎 编辑:程序博客网 时间:2024/06/03 22:57
题目链接
大神题解:
//解题思路:重点就是抓住异或的性质,两个相同的数异或等于0,
//任何数异或0结果都不变。意思就是例如 3^4^5^3^4^5^6=6 。
//然后这道题就很简单了。假设我们要使最后的结果为X,大小为4,
//那么我们可以 a^b^c^(a^b^c)^x=x,其中四个数分别为,
//a,b,c,(a^b^c)。但是a^b^c可能等于a,b,c中的一个数,
//所以我们要用一些足够特殊的数完成这个操作。题目告诉了每个数的最大值。具体看代码实现。
#include<bits/stdc++.h>using namespace std;//解题思路:重点就是抓住异或的性质,两个相同的数异或等于0,//任何数异或0结果都不变。意思就是例如 3^4^5^3^4^5^6=6 。//然后这道题就很简单了。假设我们要使最后的结果为X,大小为4,//那么我们可以 a^b^c^(a^b^c)^x=x,其中四个数分别为,//a,b,c,(a^b^c)。但是a^b^c可能等于a,b,c中的一个数,//所以我们要用一些足够特殊的数完成这个操作。题目告诉了每个数的最大值。具体看代码实现。int main(){ int n,x,i; scanf("%d%d",&n,&x); if(n==1) { printf("YES\n%d",x); return 0; } if(n==2) { if(x==0) { puts("NO"); } else { printf("YES\n0 %d",x); } return 0; } puts("YES"); for(i=0;i<n-3;++i) printf("%d ",i),x^=i; printf("%d %d %d",(1<<17)^x,(1<<19),(1<<17)^(1<<19));}////#include<iostream>//#include<deque>//#include<memory.h>//#include<stdio.h>//#include<map>//#include<string.h>//#include<algorithm>//#include<vector>//#include<math.h>//#include<stack>//#include<queue>//#include<set>//using namespace std;////int main()//{// int x,n;// cin>>n>>x;//// //n=1,2都是特殊情况,要特殊考虑// if(n==1)// cout<<"YES\n"<<x<<endl;//// if(n==2){// if(x==0)// cout<<"NO\n";// else// cout<<"YES\n0 "<<x<<endl;// }//// int temp=0;//存前i个数的异或和// int aaa=(1<<17);// int bbb=(1<<18);////// if(n>2){// cout<<"YES\n";//// //留3个数做最后的特殊处理,前i个数可以随便选,这里直接用0到n-3,但是你要记录前i个数的异或和。// for(int i=1;i<=n-3;i++){// cout<<i<<" ";// temp^=i;//记录异或和// }//// //最后把剩下的三个数,特殊输出。// //aaa,bbb,aaa^bbb会抵消掉,然后前i个数的异或和会和temp抵消掉,最后剩下x// cout<<aaa<<" "<<bbb<<" "<<(aaa^bbb^temp^x)<<endl;// }////////// return 0;//}
阅读全文
0 0
- 862C C. Mahmoud and Ehab and the xor XOR操作/构造
- 862C C. Mahmoud and Ehab and the xor XOR操作/构造
- CF 862C Mahmoud and Ehab and the xor 构造
- codeforce 862C Mahmoud and Ehab and the xor(构造)
- Codeforces 862C. Mahmoud and Ehab and the xor
- Codeforces 862C Mahmoud and Ehab and the xor
- cf 862C Mahmoud and Ehab and the xor 思维+构造
- CF C. Mahmoud and Ehab and the xor
- Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor(xor运算应用)
- Codeforces862C. Mahmoud and Ehab and the xor 【构造】
- Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)
- CF 862 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) 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
- 微信公众号开发常见问题整理
- MapKit/地图定位导航(第一篇:基本配置)
- Linux免密ssh登录
- Java编辑练习
- 黑裙安装-yellowcong
- 862C C. Mahmoud and Ehab and the xor XOR操作/构造
- 小米管培面试经历
- mysql jdbc 连接池配置
- 关于springMVC 接收json字符串集合的问题
- 【模板】埃氏筛
- Java内存分析 其一
- 剑指offer66题(1-6)
- Java练习
- 基于SpringAop操作日志实现