A - Yet Another Tetris Problem
Posted vetsama
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了A - Yet Another Tetris Problem相关的知识,希望对你有一定的参考价值。
You are given some Tetris field consisting of nn columns. The initial height of the ii-th column of the field is aiai blocks. On top of these columns you can place only figures of size 2×12×1 (i.e. the height of this figure is 22 blocks and the width of this figure is 11 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 aiai is greater than 00:
- You place one figure 2×12×1 (choose some ii from 11 to nn and replace aiai with ai+2ai+2);
- then, while all aiai are greater than zero, replace each aiai with ai−1ai−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 tt independent test cases.
Input
The first line of the input contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases.
The next 2t2t lines describe test cases. The first line of the test case contains one integer nn (1≤n≤1001≤n≤100) — the number of columns in the Tetris field. The second line of the test case contains nnintegers a1,a2,…,ana1,a2,…,an (1≤ai≤1001≤ai≤100), where aiai is the initial height of the ii-th column of the Tetris field.
Output
For each test case, print the answer — "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise.
Example
Input4 3 1 1 3 4 1 1 2 1 2 11 11 1 100OutputYES NO YES YES
水题,全奇数或全偶数就是yes,反之是no
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); int m = n; int x = 0; while (m--) { int p; scanf("%d", &p); x += (p % 2); } if (x == n || x == 0) { printf("YES "); } else { printf("NO "); } } return 0; }
以上是关于A - Yet Another Tetris Problem的主要内容,如果未能解决你的问题,请参考以下文章
6.9 VJ F - Yet Another Tetris Problem
读Martin Fowler的Yet Another Optimization Article
读Martin Fowler的Yet Another Optimization Article
D. Yet Another Yet Another Task (ST表模版 + 单调队列)