CodeForces - 1620A Equal or Not Equal

Posted 海岛Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces - 1620A Equal or Not Equal相关的知识,希望对你有一定的参考价值。

A. Equal or Not Equal
time limit per test2 seconds
memory limit per test256 megabytes

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?

Input
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).
Output
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.

Example
input
4
EEE
EN
ENNEENE
NENN
output
YES
NO
YES
YES

Note
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].

问题链接CodeForces - 1620A Equal or Not Equal
问题简述:(略)
问题分析:给出2种题解。

AC的C++语言程序如下:

/* CodeForces - 1620A Equal or Not Equal */

#include <iostream>
#include <algorithm>

using namespace std;

int main()

    string s;
    int t;
    cin >> t;
    while (t--) 
        cin >> s;

        cout << (count(s.begin(), s.end(), 'N') == 1 ? "NO" : "YES") << endl;
    

    return 0;

AC的C语言程序如下:

/* CodeForces - 1620A Equal or Not Equal */

#include <stdio.h>

#define N 50 + 1
char s[N];

int main()

    int t;
    scanf("%d", &t);
    while (t--) 
        scanf("%s", s);

        int cnt = 0;
        for (int i = 0; s[i]; i++)
            if (s[i] == 'N') cnt++;

        puts(cnt == 1 ? "NO" : "YES");
    

    return 0;

以上是关于CodeForces - 1620A Equal or Not Equal的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces A. Many Equal Substrings

B. Equal Rectangles ( Codeforces Round #579 )

Codeforces Round #486 (Div. 3) C. Equal Sums

C. Almost Equal ( Codeforces Round #580 (Div. 2) )

Make k Equal from Codeforces Round #629 (Div. 3)

Queries about less or equal elements CodeForces - 600B(二分)