A14732 | Anti Light's Cell Guessing
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are playing a game on a $n \times m$ grid, in which the computer has selected some cell $(x, y)$ of the grid, and you have to determine which one.
To do so, you will choose some $k$ and some $k$ cells $(x_1, y_1),\, (x_2, y_2), \ldots, (x_k, y_k)$ , and give them to the computer. In response, you will get $k$ numbers $b_1,\, b_2, \ldots b_k$ , where $b_i$ is the manhattan distance from $(x_i, y_i)$ to the hidden cell $(x, y)$ (so you know which distance corresponds to which of $k$ input cells).
After receiving these $b_1,\, b_2, \ldots, b_k$ , you have to be able to determine the hidden cell. What is the smallest $k$ 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 $(a_1, b_1)$ and $(a_2, b_2)$ is equal to $|a_1-a_2|+|b_1-b_2|$ .
To do so, you will choose some $k$ and some $k$ cells $(x_1, y_1),\, (x_2, y_2), \ldots, (x_k, y_k)$ , and give them to the computer. In response, you will get $k$ numbers $b_1,\, b_2, \ldots b_k$ , where $b_i$ is the manhattan distance from $(x_i, y_i)$ to the hidden cell $(x, y)$ (so you know which distance corresponds to which of $k$ input cells).
After receiving these $b_1,\, b_2, \ldots, b_k$ , you have to be able to determine the hidden cell. What is the smallest $k$ 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 $(a_1, b_1)$ and $(a_2, b_2)$ is equal to $|a_1-a_2|+|b_1-b_2|$ .
输入格式
The first line of the input contains a single integer $t$ ( $1 \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 $n$ and $m$ ( $1 \le n, m \le 10^9$ ) — the number of rows and the number of columns in the grid.
The single line of each test case contains two integers $n$ and $m$ ( $1 \le n, m \le 10^9$ ) — the number of rows and the number of columns in the grid.
输出格式
For each test case print a single integer — the minimum $k$ for that test case.
输入输出样例
输入 #1
2 2 3 3 1
输出 #1
2 1
In the first test case, the smallest such $k$ is $2$ , for which you can choose, for example, cells $(1, 1)$ and $(2, 1)$ .
Note that you can't choose cells $(1, 1)$ and $(2, 3)$ for $k = 2$ , as both cells $(1, 2)$ and $(2, 1)$ would give $b_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 = 1$ , for it you can choose cell $(3, 1)$ or $(1, 1)$ .
Note that you can't choose cells $(1, 1)$ and $(2, 3)$ for $k = 2$ , as both cells $(1, 2)$ and $(2, 1)$ would give $b_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 = 1$ , for it you can choose cell $(3, 1)$ or $(1, 1)$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted