1324A - Yet Another Tetris Problem[思维]
1324B - Yet Another Palindrome Problem[思维]
1324C - Frog Jumps[思维]
1324D - Pair of Topics[二分]
1324E - Sleeping Schedule[
d
p
dp
dp]
1324F - Count Subrectangles[树形
d
p
dp
dp]
1324A - Yet Another Tetris Problem[思维]
time limit per test | memory limit per test | input | output |
---|---|---|---|
2 seconds | 256 megabytes | standard input | standard output |
Description:
You are given some Tetris field consisting of n n n columns. The initial height of the i i i-th column of the field is a i a_i ai blocks. On top of these columns you can place only figures of size 2 × 1 2 \times 1 2×1 (i.e. the height of this figure is 2 2 2 blocks and the width of this figure is 1 1 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:
. 1. . 1. .1.The following process occurs while at least one a i a_i ai is greater than 0 0 0:
. 2. . 2. .2.You place one figure 2 × 1 2 \times 1 2×1 (choose some i i i from 1 1 1 to n and replace a i a_i ai with a i + 2 a_i+2 ai+2);
then, while all a i a_i ai are greater than zero, replace each a i a_i ai with a i − 1 a_i−1 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 t t independent test cases.
Input
The first line of the input contains one integer t ( 1 ≤ t ≤ 100 ) t (1≤t≤100) t(1≤t≤100) — the number of test cases.
The next 2 t 2t 2t lines describe test cases. The first line of the test case contains one integer n n n ( 1 ≤ n ≤ 100 ) (1≤n≤100) (1≤n≤100) — the number of columns in the Tetris field. The second line of the test case contains n n n integers a 1 , a 2 , … , a n a_1,a_2,…,a_n a1,a2,…,an ( 1 ≤ a i ≤ 100 ) (1≤a_i≤100) (1≤ai≤100), where a i a_i ai is the initial height of the i i i-th column of the Tetris field.
Output
For each test case, print the answer — “ Y E S YES YES” (without quotes) if you can clear the whole Tetris field and “ N O NO NO” otherwise.
Example input
4
3
1 1 3
4
1 1 2 1
2
11 11
1
100
Example output
YES
NO
YES
YES
Note
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 ] [2,0,2] [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 ] [0,0,0] [0,0,0].
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 ] [0,2] [0,2]. Then place the figure in the first column and after the second step of the process, the field becomes [ 0 , 0 ] [0,0] [0,0].
In the fourth test case of the example, place the figure in the first column, then the field becomes [ 102 ] [102] [102] after the first step of the process, and then the field becomes [ 0 ] [0] [0] after the second step of the process.
分析:
题意:
每个位置有高为
a
i
a_i
ai的高度,每次可以选择两种操作
1、 当
n
n
n个高度都不为
0
0
0的时候,可以全部都消去高度
1
1
1
2、 可以选择第
i
i
i-th个,使它高度变为
a
i
+
2
a_i + 2
ai+2
问最终是否可以将
n
n
n个高度都变为
0
0
0
做法:
可以发现要全部消去,则必须所有的高度都可以相同
由因为每次只能加
2
2
2,也就是意味着应该全为偶数或者全为奇数
Code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 4e5 + 5;
const int inf = 0x3f3f3f3f;
int main() {
int T;
scanf("%d", &T);
while(T--) {
int n, x, cnt = 0;
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
scanf("%d", &x);
if(x % 2) cnt++;
}
if(cnt == n || cnt == 0) puts("YES");
else puts("NO");
}
return 0;
}
1324B - Yet Another Palindrome Problem[思维]
time limit per test | memory limit per test | input | output |
---|---|---|---|
2 seconds | 256 megabytes | standard input | standard output |
Description:
You are given an array a consisting of n n n integers.
Your task is to determine if a has some subsequence of length at least 3 3 3 that is a palindrome.
Recall that an array b b b is called a subsequence of the array a a a if b can be obtained by removing some (possibly, zero) elements from a a a (not necessarily consecutive) without changing the order of remaining elements. For example, [ 2 ] , [ 1 , 2 , 1 , 3 ] [2], [1,2,1,3] [2],[1,2,1,3] and [ 2 , 3 ] [2,3] [2,3] are subsequences of [ 1 , 2 , 1 , 3 ] [1,2,1,3] [1,2,1,3], but [ 1 , 1 , 2 ] [1,1,2] [1,1,2] and [ 4 ] [4] [4] are not.
Also, recall that a palindrome is an array that reads the same backward as forward. In other words, the array a a a of length n n n is the palindrome if a i = a n − i − 1 a_i=a_{n−i−1} ai=an−i−1 for all i i i from 1 1 1 to n n n. For example, arrays [ 1234 ] , [ 1 , 2 , 1 ] , [ 1 , 3 , 2 , 2 , 3 , 1 ] [1234], [1,2,1], [1,3,2,2,3,1] [1234],[1,2,1],[1,3,2,2,3,1] and [ 10 , 100 , 10 ] [10,100,10] [10,100,10] are palindromes, but arrays [ 1 , 2 ] [1,2] [1,2] and [ 1 , 2 , 3 , 1 ] [1,2,3,1] [1,2,3,1] are not.
You have to answer t t t independent test cases.
Input
The first line of the input contains one integer t ( 1 ≤ t ≤ 100 ) t (1≤t≤100) t(1≤t≤100) — the number of test cases.
Next 2 t 2t 2t lines describe test cases. The first line of the test case contains one integer n ( 3 ≤ n ≤ 5000 ) n (3≤n≤5000) n(3≤n≤5000) — the length of a a a. The second line of the test case contains n n n integers a 1 , a 2 , … , a n a_1,a_2,…,a_n a1,a2,…,an ( 1 ≤ a i ≤ n ) (1≤a_i≤n) (1≤ai≤n), where a i a_i ai is the i i i-th element of a a a.
It is guaranteed that the sum of n n n over all test cases does not exceed 5000 5000 5000 ( ∑ n ≤ 5000 ) ( \sum n≤5000) (∑n≤5000).
Output
For each test case, print the answer — “ Y E S YES YES” (without quotes) if a a a has some subsequence of length at least 3 3 3 that is a palindrome and “ N O NO NO” otherwise.
Example input
5
3
1 2 1
5
1 2 2 3 2
3
1 1 2
4
1 2 2 1
10
1 1 2 2 3 3 4 4 5 5
Example output
YES
YES
NO
YES
NO
Note
In the first test case of the example, the array a a a has a subsequence [ 1 , 2 , 1 ] [1,2,1] [1,2,1] which is a palindrome.
In the second test case of the example, the array a a a has two subsequences of length 3 3 3 which are palindromes: [ 2 , 3 , 2 ] [2,3,2] [2,3,2] and [ 2 , 2 , 2 ] [2,2,2] [2,2,2].
In the third test case of the example, the array a has no subsequences of length at least 3 3 3 which are palindromes.
In the fourth test case of the example, the array a a a has one subsequence of length 4 4 4 which is a palindrome: [ 1 , 2 , 2 , 1 ] [1,2,2,1] [1,2,2,1] (and has two subsequences of length 3 3 3 which are palindromes: both are [ 1 , 2 , 1 ] [1,2,1] [1,2,1]).
In the fifth test case of the example, the array a a a has no subsequences of length at least 3 3 3 which are palindromes
分析:
题意:
问是否存在长度大于等于
3
3
3的回文数字串,可以不用连续的,只要前后顺序不变
例如
[
10
,
100
,
10
]
,
[
1
,
2
,
1
]
,
[
1
,
3
,
2
,
2
,
3
,
1
]
[10,100,10], [1,2,1], [1,3,2,2,3,1]
[10,100,10],[1,2,1],[1,3,2,2,3,1]
做法:
只要标记每个数字出现的一开始的位置,如果再出现判断是否中间还夹着其他数字,那么就可以
Code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e4 + 5;
const int inf = 0x3f3f3f3f;
int read() {
int x = 0, f = 0; char ch = getchar();
while(ch < '0' || ch > '9') {if(ch == '-')f = -f; ch = getchar();}
while(ch >= '0' && ch <= '9') {x = (x<<3)+(x<<1)+ch-'0'; ch = getchar();}
return x;
}
int vis[maxn];
int main() {
int T;
scanf("%d", &T);
while(T--) {
int n, x; bool flag = false;
scanf("%d", &n);
memset(vis, 0, sizeof(vis));
for(int i = 1; i <= n; ++i) {
scanf("%d", &x);
if(!vis[x]) vis[x] = i;
if(i > 1 + vis[x]) flag = true;
}
if(flag) puts("YES");
else puts("NO");
}
return 0;
}