CF1610A.Anti Light's Cell Guessing

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are playing a game on a n×mn \times m grid, in which the computer has selected some cell (x,y)(x, y) of the grid, and you have to determine which one.

To do so, you will choose some kk and some kk cells (x1,y1), (x2,y2),…,(xk,yk)(x_1, y_1),\, (x_2, y_2), \ldots, (x_k, y_k), and give them to the computer. In response, you will get kk numbers b1, b2,…bkb_1,\, b_2, \ldots b_k, where bib_i is the manhattan distance from (xi,yi)(x_i, y_i) to the hidden cell (x,y)(x, y) (so you know which distance corresponds to which of kk input cells).

After receiving these b1, b2,…,bkb_1,\, b_2, \ldots, b_k, you have to be able to determine the hidden cell. What is the smallest kk for which is it possible to always guess the hidden cell correctly, no matter what cell computer chooses?

As a reminder, the manhattan distance between cells (a1,b1)(a_1, b_1) and (a2,b2)(a_2, b_2) is equal to ∣a1−a2∣+∣b1−b2∣|a_1-a_2|+|b_1-b_2|.

你正在一个 n×mn \times m 的网格上进行一场游戏:计算机在网格中选定某个单元格 (x,y)(x, y),而你需要确定该单元格的具体位置。

为此,你需选定一个整数 kk 以及 kk 个单元格 (x1,y1), (x2,y2),…,(xk,yk)(x_1, y_1),\, (x_2, y_2), \ldots, (x_k, y_k),并将它们提交给计算机。作为回应,你将收到 kk 个整数 b1, b2,…,bkb_1,\, b_2, \ldots, b_k,其中 bib_i 表示 (xi,yi)(x_i, y_i) 到隐藏单元格 (x,y)(x, y) 的曼哈顿距离(因此你能明确知道每个 bib_i 对应于哪一个输入单元格)。

在收到这些 b1, b2,…,bkb_1,\, b_2, \ldots, b_k 后,你必须能唯一确定隐藏单元格。问:使得无论计算机选择哪个单元格,你总能正确猜出该单元格的最小 kk 是多少?

提醒:单元格 (a1,b1)(a_1, b_1) 与 (a2,b2)(a_2, b_2) 之间的曼哈顿距离定义为 ∣a1−a2∣+∣b1−b2∣|a_1-a_2|+|b_1-b_2|。

输入格式

The first line of the input contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. The description of test cases follows.

The single line of each test case contains two integers nn and mm (1≤n,m≤1091 \le n, m \le 10^9) — the number of rows and the number of columns in the grid.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例仅一行,包含两个整数 nn 和 mm(1≤n,m≤1091 \le n, m \le 10^9),分别表示网格的行数和列数。

输出格式

For each test case print a single integer — the minimum kk for that test case.

对于每个测试用例,输出一个整数——该测试用例对应的最小 kk 值。

输入输出样例

  • 输入#1

    2
    2 3
    3 1

    输出#1

    2
    1

说明/提示

In the first test case, the smallest such kk is 22, for which you can choose, for example, cells (1,1)(1, 1) and (2,1)(2, 1).

Note that you can't choose cells (1,1)(1, 1) and (2,3)(2, 3) for k=2k = 2, as both cells (1,2)(1, 2) and (2,1)(2, 1) would give b1=1,b2=2b_1 = 1, b_2 = 2, so we wouldn't be able to determine which cell is hidden if computer selects one of those.

In the second test case, you should choose k=1k = 1, for it you can choose cell (3,1)(3, 1) or (1,1)(1, 1).

在第一个测试用例中,满足条件的最小 kk 为 22,此时你可以选择例如单元格 (1,1)(1, 1) 和 (2,1)(2, 1)。

注意:当 k=2k = 2 时,你不能选择单元格 (1,1)(1, 1) 和 (2,3)(2, 3),因为此时单元格 (1,2)(1, 2) 和 (2,1)(2, 1) 都会给出 b1=1,b2=2b_1 = 1, b_2 = 2,因此若计算机从中任选其一作为隐藏单元格,我们将无法确定具体是哪一个。

在第二个测试用例中,应选择 k=1k = 1,此时你可以选择单元格 (3,1)(3, 1) 或 (1,1)(1, 1)。

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

首页