Gym - 100792C Colder-Hotter(三分交互)

Colder-Hotter

 

Statements

This is an interactive problem.

Egor and Petr are playing a game called «Colder-Hotter» on a 2D plane. At the beginning of the game Egor thinks of a point with non-negative integer coordinates not exceeding 109. Then Petr tries to guess this point: on the i-th turn he chooses some point with integer coordinates (xi, yi) and tells them to Egor. If this point is closer to the one being guessed than the previous point (xi - 1, yi - 1), then Egor answers "1". Otherwise, and also if this is the first turn of the game, he answers "0".

When there are no more turns left or Petr thinks he has enough information, he stops the game and tells his answer. If the answer is correct Petr is considered to be a winner. As Petr becomes more and more experienced, Egor reduces the number of turns.

The current limit on the number of turns in their game is 500. Petr asks you to write a program that will successfully beat Egor.

Egor is a fair player and does not change the point after the game has started.

Input

The jury program outputs either "1" in case when the current point from player is closer to the one being guessed than the previous point, or "0" when the current point from player is not closer than previous one or there is no previous point.

Output

If a player makes a turn, he must output two integer numbers with a single space character between them — x- and y-coordinates of the pronounced point (0 ≤ x, y ≤ 109). If a player wants to stop the game he must output a character 'A' and then two integer numbers — x- and y-coordinates of the guessed point, and then stop the program.

After each output (one guess or answer) you must print one end of line, flush output stream, and read the answer. See the notes if you do not know how to execute a flush command. If your program receives an EOF (end-of-file) condition on the standard input, it must exit immediately with exit code 0. Failure to comply with this requirement may result in "Time Limit Exceeded" error.

It is guaranteed that the coordinates of the point being guessed are non-negative and do not exceed 109.

Examples

Input
 
0
 
0
 
1
 
0
 
1
 
0
Output
1 1
 
0 0
 
20 20
 
20 20
 
17 239
 
17 240
 
A 17 239

Note

The point being guessed in the sample is (x = 17, y = 239). One of the possible scenarios of the game is shown:

  1. Petr names the point (1, 1) and Egor replies 0, because it is the first turn.
  2. Petr now names the point (0, 0) which is farther from (x = 17, y = 239) than (1, 0), thus Egor replies 0 again.
  3. Next point is (20, 20), and now the reply is 1.
  4. Now Petr names (20, 20) again just to show you that the answer for this case is 0, because the relation "closer" is irreflexive.
  5. Now Petr accidentally names the point (17, 239), but Egor doesn't say that this is the answer: according to the game rules he just says that it's closer to the point being guessed than the previous one.
  6. Egor answers 0 for (17, 240).
  7. Petr decides to try his fortune and names the point (17, 239). Note that he actually hasn't had enough information to be sure, so he is correct accidentally.

To flush the standard output stream, use the following statements:

In C, use fflush(stdout);

In C++, use cout.flush();

In Java, use System.out.flush(); 

 

 

第二道交互题。用有限的次数找到目标坐标点。每次访问一个坐标,都会告诉你相比上一个坐标离目标点近了还是远了。

将横纵坐标分开考虑,先固定纵坐标y(设为0),找到横坐标x,再固定横坐标x,找到纵坐标y。

因为函数图像包含凸凹点,很容易想到三分。

 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100005;

int main(void)
{
    int t,tt,x,y;
    int l=0,r=1000000000,m,mm;
    while(1){
        printf("0 0\n");
        fflush(stdout);
        scanf("%d",&t);
        m=(l+r)/2;
        mm=(m+r)/2;
        if(m==mm){
            printf("%d 0\n",l);
            fflush(stdout);
            scanf("%d",&t);
            printf("%d 0\n",m);
            fflush(stdout);
            scanf("%d",&tt);
            if(tt==1) l=m;
            else r=l;
        }
        else{
            printf("%d 0\n",m);
            fflush(stdout);
            scanf("%d",&t);
            printf("%d 0\n",mm);
            fflush(stdout);
            scanf("%d",&tt);
            if(t==1&&tt==1){
                l=m;
            }
            else{
                r=mm;
            }
        }
        if(l+1>=r) break;
    }
    if(l==r){
        x=l;
    }
    else{
        printf("0 0\n");
        fflush(stdout);
        scanf("%d",&t);
        printf("%d 0\n",l);
        fflush(stdout);
        scanf("%d",&t);
        printf("%d 0\n",r);
        fflush(stdout);
        scanf("%d",&tt);
        if(t==1&&tt==1){
            x=r;
        }
        else{
            x=l;
        }
    }
    l=0;r=1000000000;
    while(1){
        printf("%d 0\n",x);
        fflush(stdout);
        scanf("%d",&t);
        m=(l+r)/2;
        mm=(m+r)/2;
        if(m==mm){
            printf("%d %d\n",x,l);
            fflush(stdout);
            scanf("%d",&t);
            printf("%d %d\n",x,m);
            fflush(stdout);
            scanf("%d",&tt);
            if(tt==1) l=m;
            else r=l;
        }
        else{
            printf("%d %d\n",x,m);
            fflush(stdout);
            scanf("%d",&t);
            printf("%d %d\n",x,mm);
            fflush(stdout);
            scanf("%d",&tt);
            if(t==1&&tt==1){
                l=m;
            }
            else{
                r=mm;
            }
        }
        if(l+1>=r) break;
    }
    if(l==r){
        y=l;
    }
    else{
        printf("%d 0\n",x);
        fflush(stdout);
        scanf("%d",&t);
        printf("%d %d\n",x,l);
        fflush(stdout);
        scanf("%d",&t);
        printf("%d %d\n",x,r);
        fflush(stdout);
        scanf("%d",&tt);
        if(t==1&&tt==1){
            y=r;
        }
        else{
            y=l;
        }
    }
    printf("A %d %d\n",x,y);
    fflush(stdout);
    return 0;
}

 

posted @ 2018-10-30 18:40  yzm10  阅读(247)  评论(0编辑  收藏  举报