CF1934C.Find a Mine

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

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 (1≤x≤n1 \leq x \leq n) is the row number counting from the top and yy (1≤y≤m1 \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⁡(∣x−x1∣+∣y−y1∣,∣x−x2∣+∣y−y2∣)\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.

这是一个交互式问题。

你将得到一个 nn 行 mm 列的网格。坐标 (x,y)(x, y) 表示网格中的一个格子,其中 xx(1≤x≤n1 \leq x \leq n)是从上往下数的行号,yy(1≤y≤m1 \leq y \leq m)是从左往右数的列号。保证网格中恰好有 22 颗地雷,分别位于互异的格子 (x1,y1)(x_1, y_1) 和 (x2,y2)(x_2, y_2)。你最多可向交互器发起 44 次查询;在这些查询之后,你需要给出其中一颗地雷的位置。

每次查询时,你可以任选一个网格格子 (x,y)(x, y);作为回应,你将收到两颗地雷到该格子的曼哈顿距离的最小值,即你将收到数值 min⁡(∣x−x1∣+∣y−y1∣,∣x−x2∣+∣y−y2∣)\min(|x-x_1|+|y-y_1|, |x-x_2|+|y-y_2|)。

你的任务是在完成查询后,确定其中一颗地雷的位置。

输入格式

Each test contains multiple test cases. The first line of input contains a single integer tt (1≤t≤3⋅1031 \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 (2≤n≤1082 \leq n \leq 10^{8}, 2≤m≤1082 \leq m \leq 10^{8}) — the number of rows and columns.

每个测试包含多个测试用例。输入的第一行包含一个整数 tt(1≤t≤3⋅1031 \leq t \leq 3 \cdot 10^{3})—— 测试用例的数量。

每个测试用例仅有一行,包含两个整数 nn 和 mm(2≤n≤1082 \leq n \leq 10^{8},2≤m≤1082 \leq m \leq 10^{8})—— 行数和列数。

输入输出样例

  • 输入#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.

在第一个测试用例中,我们首先查询左上角单元格 (1,1)(1, 1),得到结果 33,这意味着蓝色单元格所在的反对角线上存在一颗地雷,且该地雷上方没有地雷。

下图中,每个单元格内的数字表示其到蓝色单元格的曼哈顿距离。绿色单元格是可能包含最近地雷的候选位置。

接着,我们在该反对角线上依次查询三个单元格;在最后一次查询时,得到结果 00,表明在位置 (2,3)(2, 3) 找到了一颗地雷。

第二颗地雷位于位置 (3,2)(3, 2)。

在第二个测试用例中,我们首先查询右下角单元格 (5,5)(5, 5),得到结果 11,这意味着其两个相邻单元格中有一个含有地雷,我们称其为地雷 11。

然后我们查询单元格 (2,2)(2, 2)。可以看出,这些绿色单元格与第一次查询所得的绿色单元格互不相交,因此它们包含另一颗地雷,我们称其为地雷 22。

第三次查询的单元格是 (3,3)(3, 3)。这些绿色单元格包含地雷 11,但我们仍无法确定其确切位置。然而,我们可以推断出地雷 22 的唯一可能位置是 (1,1)(1, 1),因为其余所有候选位置在本次查询中到 (3,3)(3, 3) 的距离均小于 33。

输入解题思路,AI测评打分。不知道怎么写?

首页