题目链接:https://vjudge.net/problem/Gym-100792C
转自:https://blog.csdn.net/waves___/article/details/52551857
题意:有一个坐标,猜出这个坐标。如果当前猜的坐标比上一个近,输出1,否则输出0。第一个一定输出0.
思路:直接用两个二分分别查找x,y即可。注意要用fflush刷新。在二分时,一次直接输出两个值,即当前二分的左边界和右边界,来判断哪个更近,然后继续二分。
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e9;
char s[100];
int main()
{
int x,y=0,l=0,r=maxn;
printf("0 0\n");
fflush(stdout);
scanf("%s",s);
while(l<r)
{
printf("%d %d\n",r,y);
fflush(stdout);
scanf("%s",s);
int mid=(l+r)/2;
if(s[0]=='1')
{
l=mid+1;
}
else
r=mid;
printf("%d %d\n",l,y);
fflush(stdout);
scanf("%s",s);
}
x=l;
l=0,r=maxn;
printf("%d %d\n",x,l);
fflush(stdout);
scanf("%s",s);
while(l<r)
{
printf("%d %d\n",x,r);
fflush(stdout);
scanf("%s",s);
int mid=(l+r)/2;
if(s[0]=='1')
l=mid+1;
else
r=mid;
printf("%d %d\n",x,l);
fflush(stdout);
scanf("%s",s);
}
y=l;
printf("A %d %d\n",x,y);
fflush(stdout);
return 0;
}