CF2178A.Yes or Yes
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Last Christmas, your friend Fernando gifted you a string s consisting only of the characters Y and N, representing "Yes" and "No", respectively.
You can repeatedly apply the following operation on s:
- Choose any two adjacent characters and replace them with their logical OR.
Formally, in each operation, you can choose an index i (1≤i≤∣s∣−1), remove the characters si and si+1, then insert:
- A single Y if at least one of si or si+1 is Y;
- A single N if both si and si+1 are N.
Note that after each operation, the length of s decreases by 1.
Unfortunately, Fernando does not want you to combine "Yes OR Yes", as he has experienced trauma relating to a certain song.
Determine whether it is possible to reduce s to a single character by repeatedly applying the operation above, without ever combining two Y's.
去年圣诞节,你的朋友费尔南多送给你一个仅由字符 Y 和 N 组成的字符串 s,分别代表“是(Yes)”和“否(No)”。
你可以对 s 重复执行以下操作:
- 任选两个相邻字符,并将它们替换为它们的逻辑或(logical OR)。
形式化地说,每次操作中,你可以选择一个下标 i(满足 1≤i≤∣s∣−1),删除字符 si 和 si+1,然后插入:
- 单个 Y,如果 si 或 si+1 中至少有一个是 Y;
- 单个 N,如果 si 和 si+1 均为 N。
注意:每次操作后,字符串 s 的长度减少 1。
不幸的是,费尔南多不希望你将两个 Y 进行组合(即执行“是 OR 是”),因为他曾因某首特定歌曲而遭受过心理创伤。
请判断:能否通过反复执行上述操作,将 s 化简为单个字符,且在过程中从未将两个 Y 组合在一起?
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤500). The description of the test cases follows.
The only line of each test case contains the string s (2≤∣s∣≤100). It is guaranteed that si=Y or N.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤500)。随后是测试用例的描述。
每个测试用例仅有一行,包含字符串 s(2≤∣s∣≤100)。保证字符串中每个字符 si 为 Y 或 N。
输出格式
For each test case, print "YES" if the string can be reduced to a single character by repeatedly applying the described operation, and "NO" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
对于每个测试用例,如果该字符串能通过重复应用上述操作缩减为单个字符,则输出 “YES”;否则输出 “NO”。
你可以以任意大小写形式输出答案(大写或小写均可)。例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均被视为肯定回答。
输入输出样例
输入#1
7 YY NN NNY YYYNY NNNNN YYYYYY YNNNNN
输出#1
NO YES YES NO YES NO YES
说明/提示
In the first test case, you cannot combine s1 and s2 since they are both Y. Thus, the answer is NO.
In the third test case, the following is a valid sequence of operations: NNY→NY→Y. Thus, the answer is YES.
In the fourth test case, there are two possibilities for the first operation: YYYNY→YYYY or YYYNY→YYYY. However, in either case, it is not possible to perform any more operations without combining two Y's. Thus, the answer is NO.
In the fifth test case, the following is a valid sequence of operations: NNNNN→NNNN→NNN→NN→N. Thus, the answer is YES.
在第一个测试用例中,你无法合并 s1 和 s2,因为它们均为 Y。因此,答案为 NO。
在第三个测试用例中,以下是一组合法的操作序列:NNY→NY→Y。因此,答案为 YES。
在第四个测试用例中,第一次操作有两种可能:YYYNY→YYYY 或 YYYNY→YYYY。然而,无论哪种情况,后续都无法再执行任何操作而不合并两个 Y。因此,答案为 NO。
在第五个测试用例中,以下是一组合法的操作序列:NNNNN→NNNN→NNN→NN→N。因此,答案为 YES。
输入解题思路,AI测评打分。不知道怎么写?