A14859 | Equal or Not Equal
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You had $n$ positive integers $a_1, a_2, \dots, a_n$ arranged in a circle. For each pair of neighboring numbers ( $a_1$ and $a_2$ , $a_2$ and $a_3$ , ..., $a_{n - 1}$ and $a_n$ , and $a_n$ and $a_1$ ), 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?
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?
输入格式
The first line contains a single integer $t$ ( $1 \le t \le 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 \le n \le 50$ . For each $i$ from $1$ to $n$ :
- if $s_i =$ E then $a_i$ is equal to $a_{i + 1}$ ( $a_n = a_1$ for $i = n$ );
- if $s_i =$ N then $a_i$ is not equal to $a_{i + 1}$ ( $a_n \neq a_1$ for $i = n$ ).
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 \le n \le 50$ . For each $i$ from $1$ to $n$ :
- if $s_i =$ E then $a_i$ is equal to $a_{i + 1}$ ( $a_n = a_1$ for $i = n$ );
- if $s_i =$ N then $a_i$ is not equal to $a_{i + 1}$ ( $a_n \neq a_1$ for $i = n$ ).
输出格式
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 $10^9$ .
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 $10^9$ .
输入输出样例
输入 #1
4 EEE EN ENNEENE NENN
输出 #1
YES NO YES YES
In the first test case, you can choose, for example, $a_1 = a_2 = a_3 = 5$ .
In the second test case, there is no array $a$ , since, according to $s_1$ , $a_1$ is equal to $a_2$ , but, according to $s_2$ , $a_2$ is not equal to $a_1$ .
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]$ .
In the second test case, there is no array $a$ , since, according to $s_1$ , $a_1$ is equal to $a_2$ , but, according to $s_2$ , $a_2$ is not equal to $a_1$ .
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]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted