Codeforces Round #487 (Div. 2) A. A Blend of Springtime [思维题]

A. A Blend of Springtime
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.

When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.

You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.

Input

The first and only line of input contains a non-empty string ss consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (|s|100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.

Output

Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.

You can print each letter in any case (upper or lower).

Examples
input
Copy
.BAC.
output
Copy
Yes
input
Copy
AA..CB
output
Copy
No
Note

In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.

In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.

题目:有ABC三种不同的花瓣,一个花瓣凋谢会扩散到两边,问有没有一个花瓣会有三种花ABC,我就是一个一个判断的,题解就比较简单啦(三个乘起来看一下是不是A*B*C)!!!

代码(比赛):

#include<bits/stdc++.h>
#define ll long long

using namespace std;
int n, m;
string s;
int a[3];
bool check(int c){
    memset(a, 0, sizeof(a));
    for(int i = c-1; i <= c+1; i++)
        if(s[i] != '.') a[s[i] - 'A']++;
    if(a[0] == 1&&a[1] == 1&&a[2] == 1) return true;
    else return false;
}


int main()
{
    while(cin >> s) {
        bool f = false;
        int len = s.length();
        for(int i = 1; i < len - 1; i++)
        if(check(i)) {
            f = true;
            break;
        }
        if(f) puts("Yes");
        else puts("No");
    }
    return 0;
}

代码(赛后):
#include<bits/stdc++.h>
#define ll long long

using namespace std;
int n, m, ss = ('A')*('B')*('C');
string s;
bool check(int c){
    int k = 1;
    for(int i = c - 1; i <= c+1; i++) 
    k *= s[i];
    if(k == ss) return true;
    else return false;
}


int main()
{
    while(cin >> s) {
        bool f = false;
        int len = s.length();
        for(int i = 1; i < len - 1; i++)
        if(check(i)) {
            f = true;
            break;
        }
        if(f) puts("Yes");
        else puts("No");
    }
    return 0;
}



猜你喜欢

转载自blog.csdn.net/weixin_39792252/article/details/80670266