CodeForces - 1610A Anti Light‘s Cell Guessing
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces - 1610A Anti Light‘s Cell Guessing相关的知识,希望对你有一定的参考价值。
A. Anti Light’s Cell Guessing
time limit per test1 second
memory limit per test256 megabytes
You are playing a game on a n×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 (x1,y1),(x2,y2),…,(xk,yk), and give them to the computer. In response, you will get k numbers b1,b2,…bk, where bi is the manhattan distance from (xi,yi) to the hidden cell (x,y) (so you know which distance corresponds to which of k input cells).
After receiving these b1,b2,…,bk, 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 (a1,b1) and (a2,b2) is equal to |a1−a2|+|b1−b2|.
Input
The first line of the input contains a single integer t (1≤t≤104) — 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≤n,m≤109) — the number of rows and the number of columns in the grid.
Output
For each test case print a single integer — the minimum k for that test case.
Example
input
2
2 3
3 1
output
2
1
Note
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 b1=1,b2=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).
问题链接:CodeForces - 1610A Anti Light’s Cell Guessing
问题简述:(略)
问题分析:(略)
AC的C++语言程序如下:
/* CodeForces - 1610A Anti Light's Cell Guessing */
#include <bits/stdc++.h>
using namespace std;
int main()
int t;
scanf("%d", &t);
while (t--)
int n, m;
scanf("%d%d", &n, &m);
if (n == 1 && m == 1)
printf("0\\n");
else
printf("%c\\n", min(n, m) == 1 ? '1' : '2');
return 0;
以上是关于CodeForces - 1610A Anti Light‘s Cell Guessing的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #634 D. Anti-Sudoku(构造/水)
基于simulink的Active anti-islanding-AFD主动反孤岛模型仿真