传送门:http://codeforces.com/contest/1088/problem/D
s
o
l
u
t
i
o
n
solution
solution:
比较简单的套路题
考虑确定一位需要消耗的步数
发现最坏情况要三步好像会挂?
可以发现做三步的同时能确定下一位的第一问的结果
故最坏情况需
61
61
61次操作
能过
运算优先级坑死人啊 q a q qaq qaq
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i <= k;++i)
#define repp(i,j,k) for(int i = j;i >= k;--i)
#define rept(i,x) for(int i = linkk[x];i;i = e[i].n)
#define P pair<int,int>
#define Pil pair<int,ll>
#define Pli pair<ll,int>
#define Pll pair<ll,ll>
#define pb push_back
#define pc putchar
#define mp make_pair
#define file(k) memset(k,0,sizeof(k))
#define ll long long
int rd()
{
int num = 0;char c = getchar();bool flag = true;
while(c < '0'||c > '9') {if(c == '-') flag = false;c = getchar();}
while(c >= '0' && c <= '9') num = num*10+c-48,c = getchar();
if(flag) return num;else return -num;
}
int n,mo;
//20位
int now[2];
int bin[31];
int bit[60][2];
int change(int x){return (x%mo+mo)%mo;}
void work(int x)
{//i位后都相等
repp(i,x,1)
{//每一位都是相等的
printf("? %d %d\n",now[0]+bin[i],now[1]);
fflush(stdout);
int x = rd();
if(x == -1) bit[i][0] = 1,bit[i][1] = 1; //前者小于后者
else bit[i][0] = 0,bit[i][1] = 0; //前者大于后者
}
int ans1 = 0,ans2 = 0;
rep(i,1,30) ans1 += bit[i][0] == 1?bin[i]:0,
ans2 += bit[i][1] == 1?bin[i]:0;
printf("! %d %d\n",ans1,ans2);
exit(0);
}
int main()
{
// freopen("hehe.in","r",stdin);
// freopen("hehe.out","w",stdout);
int x;
bin[1] = 1;
rep(i,2,30) bin[i] = bin[i-1]<<1;
bool f1 = false,f2 = false;
int tp = 0;
int ask[2];
repp(i,30,1)
{
if(!tp)
{
printf("? %d %d\n",now[0],now[1]);
fflush(stdout);
x = rd();
if(x == 0) work(i);
else if(x == -1) f2 = false;//前者小于后者
else f2 = true; //前者大于后者
ask[0] = ask[1] = bin[i];
printf("? %d %d\n",now[0]+ask[0],now[1]+ask[1]);
fflush(stdout);
x = rd();
if((f2 && x == -1) || (!f2 && x == 1)) bit[i][0] = f2?1:0,bit[i][1] = f2?0:1, //必定为1,0
now[0] += f2?bin[i]:0,now[1] += f2?0:bin[i];
else
{//两个相等,加判
printf("? %d %d\n",now[0]+(f2?0:ask[0]),now[1]+(f2?ask[1]:0));
fflush(stdout);
x = rd();
tp = f2?1:2;//1表示前者大于后者,反之为后者大于前者
if(f2) if(x == -1) bit[i][0] = bit[i][1] = 0;
else bit[i][0] = bit[i][1] = 1;
else if(x == -1) bit[i][0] = bit[i][1] = 1;
else bit[i][0] = bit[i][1] = 0;
}
}
else
{
if(tp == 1) f2 = true;
else f2 = false;
tp = 0;
ask[0] = ask[1] = bin[i];
printf("? %d %d\n",now[0]+ask[0],now[1]+ask[1]);
fflush(stdout);
x = rd();
if((f2 && x == -1) || (!f2 && x == 1)) bit[i][0] = f2?1:0,bit[i][1] = f2?0:1, //必定为1,0
now[0] += f2?bin[i]:0,now[1] += f2?0:bin[i];
else
{//两个相等,加判
printf("? %d %d\n",now[0]+(f2?0:ask[0]),now[1]+(f2?ask[1]:0));
fflush(stdout);
x = rd();
tp = f2?1:2;//1表示前者大于后者,反之为后者大于前者
if(f2) if(x == -1) bit[i][0] = bit[i][1] = 0;
else bit[i][0] = bit[i][1] = 1;
else if(x == -1) bit[i][0] = bit[i][1] = 1;
else bit[i][0] = bit[i][1] = 0;
}
}
}
int ans1 = 0,ans2 = 0;
rep(i,1,30) ans1 += bit[i][0] == 1?bin[i]:0,
ans2 += bit[i][1] == 1?bin[i]:0;
printf("! %d %d\n",ans1,ans2);
return 0;
}