311102: CF1934C. Find a Mine
Description
This is an interactive problem.
You are given a grid with $n$ rows and $m$ columns. The coordinates $(x, y)$ represent the cell on the grid, where $x$ ($1 \leq x \leq n$) is the row number counting from the top and $y$ ($1 \leq y \leq m$) is the column number counting from the left. It is guaranteed that there are exactly $2$ mines in the grid at distinct cells, denoted as $(x_1, y_1)$ and $(x_2, y_2)$. You are allowed to make no more than $4$ 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)$, 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(|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.
InputEach test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \leq t \leq 3 \cdot 10^{3}$) — the number of test cases.
The only line of each test case contains two integers $n$ and $m$ ($2 \leq n \leq 10^{8}$, $2 \leq m \leq 10^{8}$) — the number of rows and columns.
InteractionFor each test case, the interaction starts with reading $n$ and $m$.
Then you are allowed to make at most $4$ queries in the following way:
"? x y" ($1 \leq x \leq n$ and $1 \leq y \leq m$)
After each one, you should read an integer $d$ which is equal to $\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 $t$ ($1 \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 $n$ and $m$ ($2 \leq n \leq 10^{8}$, $2 \leq m \leq 10^{8}$) — the number of rows and columns.
The second line contains the coordinates of the first mine $x_1$ and $y_1$($1 \leq x_1 \leq n$, $1 \leq y_1 \leq m$).
The third line contains the coordinates of the second mine $x_2$ and $y_2$($1 \leq x_2 \leq n$, $1 \leq y_2 \leq m$).
The mines should be located at different positions.
ExampleInput2 4 4 3 2 2 0 5 5 1 2 3Output
? 1 1 ? 1 4 ? 4 1 ? 2 3 ! 2 3 ? 5 5 ? 2 2 ? 3 3 ! 1 1Note
In the first test case, we start by querying the upper-left corner $(1, 1)$ and get the result $3$, 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 $0$, which means that a mine is found at the position $(2, 3)$.
The second mine was located at the position $(3, 2)$.
In the second test case, we start by asking the lower-right corner $(5, 5)$, and get the result $1$, which means that one of the two neighbours contains a mine, let's call it mine $1$.
Then we ask cell $(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 $2$.
Query $3$ is cell $(3, 3)$. These cells contain mine $1$, but we still don't know where exactly. Nevertheless, we can determine that the only possible cell for mine $2$ is $(1, 1)$, because all other candidates are at a distance closer than $3$ for this query.
Output
在每个查询中,你可以选择任意的网格单元格 (x, y),作为回报,你将收到两个地雷到所选单元格的曼哈顿距离的最小值,即你将收到值 \(\min(|x-x_1|+|y-y_1|, |x-x_2|+|y-y_2|)\)。
你的任务是,在提出查询后确定其中一个地雷的位置。
输入输出数据格式:
- 输入:
- 第一行包含一个整数 t(1 ≤ t ≤ 3 × 10^3)——测试用例的数量。
- 每个测试用例包含一行,有两个整数 n 和 m(2 ≤ n ≤ 10^8,2 ≤ m ≤ 10^8)——行数和列数。
- 交互:
- 对于每个测试用例,交互从读取 n 和 m 开始。
- 然后你可以以以下方式提出最多 4 个查询:
- "? x y" (1 ≤ x ≤ n 且 1 ≤ y ≤ m)
- 在每个查询之后,你应该读取一个整数 d,其等于 \(\min(|x-x_1|+|y-y_1|, |x-x_2|+|y-y_2|)\)。
- 当你找到任一地雷的位置时,打印一行 "! x y"(不带引号),代表一个地雷的行和列。输出答案不计入查询次数。
- 打印答案后,你的程序必须继续解决剩余的测试用例,或者如果所有测试用例都已解决,则退出。
- 此问题的交互器不是自适应的:在提出任何查询之前,地雷的单元格就已固定。
- 在打印查询后,不要忘记输出行尾并刷新输出。否则,你会得到“空闲限制超出”。为此,请使用相应语言的方法来刷新输出。
请注意,这里提供的格式是根据问题描述翻译的,具体的编程实现可能需要根据所使用的编程语言和平台进行调整。题目大意:这是一个交互式问题。你有一个有 n 行 m 列的网格,坐标 (x, y) 代表网格上的一个单元格,其中 x(1 ≤ x ≤ n)是从顶部开始的行号,y(1 ≤ y ≤ m)是从左边开始的列号。保证网格中恰好有 2 个地雷,位于不同的单元格,分别表示为 (x1, y1) 和 (x2, y2)。你可以向交互器提出最多 4 个查询,在这些查询之后,你需要提供其中一个地雷的位置。 在每个查询中,你可以选择任意的网格单元格 (x, y),作为回报,你将收到两个地雷到所选单元格的曼哈顿距离的最小值,即你将收到值 \(\min(|x-x_1|+|y-y_1|, |x-x_2|+|y-y_2|)\)。 你的任务是,在提出查询后确定其中一个地雷的位置。 输入输出数据格式: - 输入: - 第一行包含一个整数 t(1 ≤ t ≤ 3 × 10^3)——测试用例的数量。 - 每个测试用例包含一行,有两个整数 n 和 m(2 ≤ n ≤ 10^8,2 ≤ m ≤ 10^8)——行数和列数。 - 交互: - 对于每个测试用例,交互从读取 n 和 m 开始。 - 然后你可以以以下方式提出最多 4 个查询: - "? x y" (1 ≤ x ≤ n 且 1 ≤ y ≤ m) - 在每个查询之后,你应该读取一个整数 d,其等于 \(\min(|x-x_1|+|y-y_1|, |x-x_2|+|y-y_2|)\)。 - 当你找到任一地雷的位置时,打印一行 "! x y"(不带引号),代表一个地雷的行和列。输出答案不计入查询次数。 - 打印答案后,你的程序必须继续解决剩余的测试用例,或者如果所有测试用例都已解决,则退出。 - 此问题的交互器不是自适应的:在提出任何查询之前,地雷的单元格就已固定。 - 在打印查询后,不要忘记输出行尾并刷新输出。否则,你会得到“空闲限制超出”。为此,请使用相应语言的方法来刷新输出。 请注意,这里提供的格式是根据问题描述翻译的,具体的编程实现可能需要根据所使用的编程语言和平台进行调整。