题目链接:https://codeforces.com/contest/1088/problem/D
题目大意:有a和b,可以通过? c d提问,返回a^c和b^d比较大小的结果,要求通过最多62次查询得到答案。
题目思路:由于数字高位能决定一个数字的大小,所以从大到小看。每一位都看,先让a的该位取反,然后让b。如果都是1的话,那么先让a取反那第一个必定小于第二个,让b取反第一个必大于第二个。如果都是0则恰巧相反。如果两个数字不同的话,就要看之前存储的一个num。两个数字大小的比较是从高位到低位第一个不同的位置开始比较。当两个数字不同时,让任一一个数字取反,该位的数字会变成相同,得到的结果是该位以后的数字的大小比较结果,也就给出了下一个两个数字不同时哪个是1。
以下是代码:
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<math.h>
using namespace std;
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
const int MAXN = 1e5+5;
const int MOD = 1e9+7;
char s[15];
int main(){
int a,x,y;
int ans1=0,ans2=0,big;
printf("? 0 0\n");
fflush(stdout);
scanf("%d",&big);
per(i,29,0){
a=1<<i;
printf("? %d %d\n",ans1+a,ans2);
fflush(stdout);
scanf("%d",&x);
printf("? %d %d\n",ans1,ans2+a);
fflush(stdout);
scanf("%d",&y);
if(x!=y&&x==-1){
ans1+=a,ans2+=a;
}
if(x==y){
if(big==1)ans1+=a;
else if(big==-1) ans2+=a;
big=x;
}
}
printf("! %d %d\n",ans1,ans2);
fflush(stdout);
return 0;
}