CF1324A.Yet Another Tetris Problem
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given some Tetris field consisting of n columns. The initial height of the i-th column of the field is ai blocks. On top of these columns you can place only figures of size 2×1 (i.e. the height of this figure is 2 blocks and the width of this figure is 1 block). Note that you cannot rotate these figures.
Your task is to say if you can clear the whole field by placing such figures.
More formally, the problem can be described like this:
The following process occurs while at least one ai is greater than 0:
- You place one figure 2×1 (choose some i from 1 to n and replace ai with ai+2);
- then, while all ai are greater than zero, replace each ai with ai−1.
And your task is to determine if it is possible to clear the whole field (i.e. finish the described process), choosing the places for new figures properly.
You have to answer t independent test cases.
给你一个由 n 列组成的俄罗斯方块游戏区域。第 i 列的初始高度为 ai 个方块。你只能在这些列的顶部放置尺寸为 2×1 的方块(即该方块高度为 2 个方块,宽度为 1 个方块)。注意:你不能旋转这些方块。
你的任务是判断:是否可以通过合理放置此类方块,将整个区域完全清空。
更形式化地,该问题可描述如下:
只要至少存在一个 ai>0,就重复执行以下过程:
- 放置一个 2×1 方块(选择某个 i(1≤i≤n),并将 ai 替换为 ai+2);
- 然后,只要所有 ai 均大于 0,就将每个 ai 同时减去 1。
你的任务是判断:是否存在一种对新方块放置位置的合理选择方式,使得上述过程能够终止(即最终所有 ai=0)。
你需要回答 t 个相互独立的测试用例。
输入格式
The first line of the input contains one integer t (1≤t≤100) — the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1≤n≤100) — the number of columns in the Tetris field. The second line of the test case contains n integers a1,a2,…,an (1≤ai≤100), where ai is the initial height of the i-th column of the Tetris field.
输入的第一行包含一个整数 t(1≤t≤100),表示测试用例的数量。
接下来的 2t 行描述了各测试用例。每个测试用例的第一行包含一个整数 n(1≤n≤100),表示俄罗斯方块游戏区域的列数。每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤100),其中 ai 表示俄罗斯方块游戏区域中第 i 列的初始高度。
输出格式
For each test case, print the answer — "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise.
对于每个测试用例,如果可以清空整个俄罗斯方块(Tetris)游戏区域,则输出答案 "YES"(不带引号),否则输出 "NO"。
输入输出样例
输入#1
4 3 1 1 3 4 1 1 2 1 2 11 11 1 100
输出#1
YES NO YES YES
说明/提示
The first test case of the example field is shown below:

Gray lines are bounds of the Tetris field. Note that the field has no upper bound.
One of the correct answers is to first place the figure in the first column. Then after the second step of the process, the field becomes [2,0,2]. Then place the figure in the second column and after the second step of the process, the field becomes [0,0,0].
And the second test case of the example field is shown below:

It can be shown that you cannot do anything to end the process.
In the third test case of the example, you first place the figure in the second column after the second step of the process, the field becomes [0,2]. Then place the figure in the first column and after the second step of the process, the field becomes [0,0].
In the fourth test case of the example, place the figure in the first column, then the field becomes [102] after the first step of the process, and then the field becomes [0] after the second step of the process.
示例中的第一个测试用例的方块区域如下所示:

灰色线条表示俄罗斯方块区域的边界。注意:该区域没有上边界。
一种正确的解法是:首先将方块放置在第一列;经过该操作的第二步后,区域状态变为 [2,0,2];然后将方块放置在第二列,再经过该操作的第二步后,区域状态变为 [0,0,0]。
示例中的第二个测试用例的方块区域如下所示:

可以证明:无法进行任何操作以使过程终止。
在示例的第三个测试用例中,首先将方块放置在第二列,经过该操作的第二步后,区域状态变为 [0,2];然后将方块放置在第一列,再经过该操作的第二步后,区域状态变为 [0,0]。
在示例的第四个测试用例中,将方块放置在第一列,经过该操作的第一步后,区域状态变为 [102],再经过该操作的第二步后,区域状态变为 [0]。
输入解题思路,AI测评打分。不知道怎么写?