CF1620A.Equal or Not Equal
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You had n positive integers a1,a2,…,an arranged in a circle. For each pair of neighboring numbers (a1 and a2, a2 and a3, ..., an−1 and an, and an and a1), you wrote down: are the numbers in the pair equal or not.
Unfortunately, you've lost a piece of paper with the array a. Moreover, you are afraid that even information about equality of neighboring elements may be inconsistent. So, you are wondering: is there any array a which is consistent with information you have about equality or non-equality of corresponding pairs?
你有 n 个正整数 a1,a2,…,an,它们按环形排列。对于每一对相邻的数(即 a1 与 a2、a2 与 a3、……、an−1 与 an,以及 an 与 a1),你记录下了:该对中的两个数是否相等。
不幸的是,你丢失了写有数组 a 的那张纸。此外,你还担心关于相邻元素是否相等的信息本身可能存在矛盾。因此,你开始思考:是否存在某个数组 a,使得它与你所掌握的关于各相邻数对是否相等(或不相等)的信息完全一致?
输入格式
The first line contains a single integer t (1≤t≤1000) — the number of test cases. Next t cases follow.
The first and only line of each test case contains a non-empty string s consisting of characters E and/or N. The length of s is equal to the size of array n and 2≤n≤50. For each i from 1 to n:
- if si= E then ai is equal to ai+1 (an=a1 for i=n);
- if si= N then ai is not equal to ai+1 (an=a1 for i=n).
第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。接下来是 t 个测试用例。
每个测试用例仅有一行,包含一个非空字符串 s,其字符仅由 E 和/或 N 组成。字符串 s 的长度等于数组 n 的大小,且满足 2≤n≤50。对于每个从 1 到 n 的 i:
- 若 si= E,则 ai=ai+1(当 i=n 时,规定 an=a1);
- 若 si= N,则 ai=ai+1(当 i=n 时,规定 an=a1)。
输出格式
For each test case, print YES if it's possible to choose array a that are consistent with information from s you know. Otherwise, print NO.
It can be proved, that if there exists some array a, then there exists an array a of positive integers with values less or equal to 109.
对于每个测试用例,如果能够选择一个与已知信息 s 一致的数组 a,则输出 YES;否则输出 NO。
可以证明:若存在某个数组 a,则必存在一个由不超过 109 的正整数组成的数组 a。
输入输出样例
输入#1
4 EEE EN ENNEENE NENN
输出#1
YES NO YES YES
说明/提示
In the first test case, you can choose, for example, a1=a2=a3=5.
In the second test case, there is no array a, since, according to s1, a1 is equal to a2, but, according to s2, a2 is not equal to a1.
In the third test case, you can, for example, choose array a=[20,20,4,50,50,50,20].
In the fourth test case, you can, for example, choose a=[1,3,3,7].
在第一个测试用例中,你可以选择,例如,a1=a2=a3=5。
在第二个测试用例中,不存在满足条件的数组 a,因为根据 s1,a1 等于 a2,但根据 s2,a2 不等于 a1。
在第三个测试用例中,你可以选择,例如,数组 a=[20,20,4,50,50,50,20]。
在第四个测试用例中,你可以选择,例如,a=[1,3,3,7]。
输入解题思路,AI测评打分。不知道怎么写?