Codeforces Round #440 (Div. 1) B. Something with XOR Query
来源:互联网 发布:税收数据质量管理 编辑:程序博客网 时间:2024/05/06 16:05
题目大意
给一个排列p和每个数对应的位置b,你可以询问2n次,每次两个数i,j,返回p[i]^b[j],求最后如果询问n^2次都不能确定的排列个数。
题解
询问所有0,i和i,0,之后就能得知所有数的两两异或(a[i][j]=a[i][0] ^ a[0][j] ^a[0][0]),然后就枚举第一个数是什么,暴力计算即可。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;int read(){ char ch=getchar();int f=0; while(ch<'0'||ch>'9') ch=getchar(); while(ch>='0'&&ch<='9') {f=f*10+(ch^48);ch=getchar();} return f;}int num[5005][5005],a[5005],b[5005],ans[5005];bool vis[50005];int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++) { printf("? %d %d\n",0,i); fflush(stdout); int x; scanf("%d",&x); num[0][i]=x; } for(int i=1;i<n;i++) { printf("? %d %d\n",i,0); fflush(stdout); int x; scanf("%d",&x); num[i][0]=x; } for(int i=1;i<n;i++) { for(int j=1;j<n;j++) { num[i][j]=num[0][0]^num[i][0]^num[0][j]; } } int first=-1,sum=0; for(int i=0;i<n;i++) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); a[0]=i;bool ac=1; for(int j=0;j<n;j++) { b[j]=(num[0][j]^a[0]); } for(int j=1;j<n;j++) { a[j]=(num[j][0]^b[0]); } memset(vis,0,sizeof(vis)); for(int j=0;j<n;j++) { if(!vis[a[j]]&&a[j]<n) { vis[a[j]]=1; } else { ac=0; break; } } if(ac) { for(int j=0;j<n;j++) { if(b[j]<n&&a[b[j]]!=j) { ac=0; break; } } } if(ac) { sum++; if(first==-1) { first=i; for(int j=0;j<n;j++) { ans[j]=a[j]; } } } } printf("!\n"); printf("%d\n",sum); for(int i=0;i<n;i++) { printf("%d ",ans[i]); } fflush(stdout);}
阅读全文
0 0
- Codeforces Round #440 (Div. 1) B. Something with XOR Query
- Codeforces Round #449 (Div. 1) B. Ithea Plays With Chtholly
- Codeforces Round #245 (Div. 1)——Xor-tree
- Codeforces Round #172 (Div. 1) BMaximum Xor Secondary 单调栈
- Codeforces Round #440 (Div. 2) A B
- Codeforces Round #131 (Div. 1) B. Numbers
- Codeforces Round #119 (Div. 1) B. AlgoRace
- Codeforces Round #215 (Div. 1) <A-B>
- Codeforces Round #225 (Div. 1) B. Volcanoes
- Codeforces Round #230 (Div. 1)B,C
- Codeforces Round #239 (Div. 1)(A,B)
- Codeforces Round #253 (Div. 1)-A,B
- Codeforces Round #254 (Div. 1)-A,B
- Codeforces Round #240 (Div. 1)B
- Codeforces Round #259 (Div. 1) B题
- Codeforces Round #268 (Div. 1) B
- Codeforces Round #282 (Div. 1) B
- Codeforces Round #284 (Div. 1) B
- 10.15PCA
- angularjs 初使用2
- Codeforces Round #440 div2 A. Search for Pretty Integers
- 【数论】[HNOI2006]鬼谷子的钱袋
- angularjs $http请求--图书
- Codeforces Round #440 (Div. 1) B. Something with XOR Query
- angular制作购物车
- RecyclerView
- 购物车综合练习题angular js
- HDU 5943 Kingdom of Obsession(二分图匹配+数论)
- 原购物车只有删除和查询
- Codeforces Round #440 div2 C. Maximum splitting
- 竞赛反思
- cocos2d-js 3.0 RC0 手动绑定 C++调用js,js调用C++ jsbinding