RPD and Rap Sheet (Easy Version)
https://www.luogu.com.cn/problem/CF1543D1
题意:
输入
5 2
0
0
1
输出
3
4
5
思路:
运用异或自反的性质
$x\oplus z=y $ 可转化为 $ x\oplus y=z$
之后再枚举从0往后猜,第一次猜0,之后每次猜i⊕(i-1),就可以做到猜i的效果。
(x⊕(i−1))⊕(i⊕(i−1)) =x⊕(i−1)⊕i⊕(i−1)=x⊕i
代码:
#include<bits/stdc++.h>
using namespace std;
int t,n,k,x;
int main(){
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++){
if(!i){
printf("0\n");
fflush(stdout);
scanf("%d",&x);
if(x) break;
}else{
printf("%d\n",i^(i-1));
fflush(stdout);
scanf("%d",&x);
if(x) break;
}
}
}
return 0;
}