309871: CF1749A. Cowardly Rooks

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Cowardly Rooks

题意翻译

在 n*n 的国际象棋棋盘中已放置了 $m$ 个车,满足: - 没有两个车在同一格里; - 没有两个车能攻击对方(即没有两个车在同一列或同一行里)。 判断是否可能恰好对于某一个车(由您来选择)移动一次(前往同一列或同一行内非本格的任意格),使得形成的盘面还满足上面的条件?

题目描述

There's a chessboard of size $ n \times n $ . $ m $ rooks are placed on it in such a way that: - no two rooks occupy the same cell; - no two rooks attack each other. A rook attacks all cells that are in its row or column. Is it possible to move exactly one rook (you can choose which one to move) into a different cell so that no two rooks still attack each other? A rook can move into any cell in its row or column if no other rook stands on its path.

输入输出格式

输入格式


The first line contains a single integer $ t $ ( $ 1 \le t \le 2000 $ ) — the number of testcases. The first line of each testcase contains two integers $ n $ and $ m $ ( $ 1 \le n, m \le 8 $ ) — the size of the chessboard and the number of the rooks. The $ i $ -th of the next $ m $ lines contains two integers $ x_i $ and $ y_i $ ( $ 1 \le x_i, y_i \le n $ ) — the position of the $ i $ -th rook: $ x_i $ is the row and $ y_i $ is the column. No two rooks occupy the same cell. No two rooks attack each other.

输出格式


For each testcase, print "YES" if it's possible to move exactly one rook into a different cell so that no two rooks still attack each other. Otherwise, print "NO".

输入输出样例

输入样例 #1

2
2 2
1 2
2 1
3 1
2 2

输出样例 #1

NO
YES

说明

In the first testcase, the rooks are in the opposite corners of a $ 2 \times 2 $ board. Each of them has a move into a neighbouring corner, but moving there means getting attacked by another rook. In the second testcase, there's a single rook in a middle of a $ 3 \times 3 $ board. It has $ 4 $ valid moves, and every move is fine because there's no other rook to attack it.

Input

题意翻译

在 n*n 的国际象棋棋盘中已放置了 $m$ 个车,满足: - 没有两个车在同一格里; - 没有两个车能攻击对方(即没有两个车在同一列或同一行里)。 判断是否可能恰好对于某一个车(由您来选择)移动一次(前往同一列或同一行内非本格的任意格),使得形成的盘面还满足上面的条件?

Output

**题目大意:**

在国际象棋的 $ n \times n $ 棋盘上,已经放置了 $ m $ 个车(rook),满足以下条件:

- 没有两个车在同一格上;
- 没有两个车能够相互攻击(即没有两个车在同一列或同一行上)。

判断是否可能恰好移动一个车(您可以决定移动哪一个),使得移动后的棋盘仍然满足上述条件。车可以移动到同一行或同一列中的任意空格。

**输入输出数据格式:**

**输入格式:**
- 第一行包含一个整数 $ t $($ 1 \le t \le 2000 $),表示测试用例的数量。
- 每个测试用例的第一行包含两个整数 $ n $ 和 $ m $($ 1 \le n, m \le 8 $),分别表示棋盘的大小和车的数量。
- 接下来的 $ m $ 行,每行包含两个整数 $ x_i $ 和 $ y_i $($ 1 \le x_i, y_i \le n $),表示第 $ i $ 个车的位置,$ x_i $ 是行号,$ y_i $ 是列号。
- 保证没有两个车在同一格上,且没有两个车能相互攻击。

**输出格式:**
- 对于每个测试用例,如果可以移动一个车到不同的格子使得棋盘仍然满足条件,则输出 "YES",否则输出 "NO"。**题目大意:** 在国际象棋的 $ n \times n $ 棋盘上,已经放置了 $ m $ 个车(rook),满足以下条件: - 没有两个车在同一格上; - 没有两个车能够相互攻击(即没有两个车在同一列或同一行上)。 判断是否可能恰好移动一个车(您可以决定移动哪一个),使得移动后的棋盘仍然满足上述条件。车可以移动到同一行或同一列中的任意空格。 **输入输出数据格式:** **输入格式:** - 第一行包含一个整数 $ t $($ 1 \le t \le 2000 $),表示测试用例的数量。 - 每个测试用例的第一行包含两个整数 $ n $ 和 $ m $($ 1 \le n, m \le 8 $),分别表示棋盘的大小和车的数量。 - 接下来的 $ m $ 行,每行包含两个整数 $ x_i $ 和 $ y_i $($ 1 \le x_i, y_i \le n $),表示第 $ i $ 个车的位置,$ x_i $ 是行号,$ y_i $ 是列号。 - 保证没有两个车在同一格上,且没有两个车能相互攻击。 **输出格式:** - 对于每个测试用例,如果可以移动一个车到不同的格子使得棋盘仍然满足条件,则输出 "YES",否则输出 "NO"。

加入题单

算法标签: