CF1934C.Find a Mine

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is an interactive problem.

You are given a grid with nn rows and mm columns. The coordinates (x,y)(x, y) represent the cell on the grid, where xx ( 1xn1 \leq x \leq n ) is the row number counting from the top and yy ( 1ym1 \leq y \leq m ) is the column number counting from the left. It is guaranteed that there are exactly 22 mines in the grid at distinct cells, denoted as (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) . You are allowed to make no more than 44 queries to the interactor, and after these queries, you need to provide the location of one of the mines.

In each query, you can choose any grid cell (x,y)(x, y) , and in return, you will receive the minimum Manhattan distance from both the mines to the chosen cell, i.e., you will receive the value min(xx1+yy1,xx2+yy2)\min(|x-x_1|+|y-y_1|, |x-x_2|+|y-y_2|) .

Your task is to determine the location of one of the mines after making the queries.

输入格式

Each test contains multiple test cases. The first line of input contains a single integer tt ( 1t31031 \leq t \leq 3 \cdot 10^{3} ) — the number of test cases.

The only line of each test case contains two integers nn and mm ( 2n1082 \leq n \leq 10^{8} , 2m1082 \leq m \leq 10^{8} ) — the number of rows and columns.

输出格式

For each test case, the interaction starts with reading nn and mm .

Then you are allowed to make at most 44 queries in the following way:

"? x y" ( 1xn1 \leq x \leq n and 1ym1 \leq y \leq m )

After each one, you should read an integer dd which is equal to min(xx1+yy1,xx2+yy2)\min(|x-x_1|+|y-y_1|, |x-x_2|+|y-y_2|) .

When you have found the location of any one of the mines, print a single line "! x y" (without quotes), representing the row and the column of one of the mines. Outputting the answer does not count as a query.

After printing the answer, your program must then continue to solve the remaining test cases, or exit if all test cases have been solved.

The interactor for this problem is not adaptive: cells of mines are fixed before any queries are made.

After printing a query, do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see the documentation for other languages.

Hacks:

To make a hack, use the following format:

The first line contains a single integer tt ( 1t31031 \leq t \leq 3 \cdot 10^{3} ) — the number of test cases.

The description of each test case should consist of three lines.

The first line contains two integers nn and mm ( 2n1082 \leq n \leq 10^{8} , 2m1082 \leq m \leq 10^{8} ) — the number of rows and columns.

The second line contains the coordinates of the first mine x1x_1 and y1y_1 ( 1x1n1 \leq x_1 \leq n , 1y1m1 \leq y_1 \leq m ).

The third line contains the coordinates of the second mine x2x_2 and y2y_2 ( 1x2n1 \leq x_2 \leq n , 1y2m1 \leq y_2 \leq m ).

The mines should be located at different positions.

输入输出样例

  • 输入#1

    2
    4 4
    
    3
    
    2
    
    2
    
    0
    
    5 5
    
    1
    
    2
    
    3

    输出#1

    ? 1 1
    
    ? 1 4
    
    ? 4 1
    
    ? 2 3
    
    ! 2 3
    
    ? 5 5
    
    ? 2 2
    
    ? 3 3
    
    ! 1 1

说明/提示

In the first test case, we start by querying the upper-left corner (1,1)(1, 1) and get the result 33 , which means that there is a mine on the counter diagonal, and there is no mine above it.

In the image below, each cell contains a number indicating the distance to the blue cell. The green cells are candidates to contain the nearest mine.

Then we ask three cells on that diagonal, and at the last query, we get the result 00 , which means that a mine is found at the position (2,3)(2, 3) .

The second mine was located at the position (3,2)(3, 2) .

In the second test case, we start by asking the lower-right corner (5,5)(5, 5) , and get the result 11 , which means that one of the two neighbours contains a mine, let's call it mine 11 .

Then we ask cell (2,2)(2, 2) . We can see that these green cells don't intersect with the green cells from the first query, so they contain the other mine, let's call it mine 22 .

Query 33 is cell (3,3)(3, 3) . These cells contain mine 11 , but we still don't know where exactly. Nevertheless, we can determine that the only possible cell for mine 22 is (1,1)(1, 1) , because all other candidates are at a distance closer than 33 for this query.

首页