CF1345A.Puzzle Pieces

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a special jigsaw puzzle consisting of n⋅mn\cdot m identical pieces. Every piece has three tabs and one blank, as pictured below.

The jigsaw puzzle is considered solved if the following conditions hold:

  1. The pieces are arranged into a grid with nn rows and mm columns.
  2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.

Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.

你被给定一个特殊的拼图,它由 n⋅mn\cdot m 个完全相同的拼图块组成。每一块都有三个凸起(tab)和一个凹槽(blank),如下图所示:

当满足以下条件时,该拼图被视为已解出:

  1. 所有拼图块被排列成一个 nn 行 mm 列的网格;
  2. 对于网格中任意两个共享一条边的拼图块,其中一个块的某个凸起必须恰好嵌入另一个块的某个凹槽中。

在允许对拼图块进行任意旋转和平移的前提下,请判断该拼图是否可能被解出。

输入格式

The test consists of multiple test cases. The first line contains a single integer tt (1≤t≤10001\le t\le 1000) — the number of test cases. Next tt lines contain descriptions of test cases.

Each test case contains two integers nn and mm (1≤n,m≤1051 \le n,m \le 10^5).

测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001\le t\le 1000),表示测试用例的数量。接下来的 tt 行分别描述各个测试用例。

每个测试用例包含两个整数 nn 和 mm(1≤n,m≤1051 \le n,m \le 10^5)。

输出格式

For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).

对于每个测试用例,如果能够完成该拼图,则输出一行包含 "YES";否则输出 "NO"。每个字母可以以任意大小写形式输出(大写或小写)。

输入输出样例

  • 输入#1

    3
    1 3
    100000 100000
    2 2

    输出#1

    YES
    NO
    YES

说明/提示

For the first test case, this is an example solution:

For the second test case, we can show that no solution exists.

For the third test case, this is an example solution:

对于第一个测试用例,这是一个示例解:

对于第二个测试用例,我们可以证明不存在解。

对于第三个测试用例,这是一个示例解:

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

首页