Codeforces Edu 33 A 893A Chess For Three

若校学渣第一次来写博客了,虽然已经大三了,但是还是希望我的博客对新手有帮助吧

A. Chess For Three
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it’s a bit difficult for them because chess is a game for two players, not three.

So they play with each other according to following rules:

Alex and Bob play the first game, and Carl is spectating;
When the game ends, the one who lost the game becomes the spectator in the next game, and the one who was spectating plays against the winner.
Alex, Bob and Carl play in such a way that there are no draws.

Today they have played n games, and for each of these games they remember who was the winner. They decided to make up a log of games describing who won each game. But now they doubt if the information in the log is correct, and they want to know if the situation described in the log they made up was possible (that is, no game is won by someone who is spectating if Alex, Bob and Carl play according to the rules). Help them to check it!

Input
The first line contains one integer n (1 ≤ n ≤ 100) — the number of games Alex, Bob and Carl played.

Then n lines follow, describing the game log. i-th line contains one integer ai (1 ≤ ai ≤ 3) which is equal to 1 if Alex won i-th game, to 2 if Bob won i-th game and 3 if Carl won i-th game.

Output
Print YES if the situation described in the log was possible. Otherwise print NO.

Examples
input
3
1
1
2
output
YES
input
2
1
2
output
NO

题意:有三个人,A,B,C在下棋,A,B先对战,然后输的人要让位给下一个人。问你,所给出的序列是否可行。
思路:直接模拟就好。

#include<bits/stdc++.h>
using namespace std ;

int a[105] ;

int main()
{
    int n ;
    cin >> n ;
    for(int i = 0 ; i < n ; i ++)
    {
        cin >> a[i] ;
    }
    if(a[0] != 1 && a[0] != 2)
    {
        cout << "NO" << endl ;
        return 0 ;
    }
    int win = a[0] ;
    int lost ;
    if(win == 1)
    {
        lost = 2 ;
    }
    if(win == 2)
    {
        lost = 1 ;
    }
    for(int i = 1 ; i < n ; i ++)
    {
        if(a[i] == lost)
        {
            cout << "NO" << endl;
            return 0 ;
        }
        win = a[i] ;
        for(int j = 1 ; j <=3 ; j ++)
        {
            if(j != lost && j != a[i])
            {
                lost = j ;
                break ;
            }
        }
    }
    cout << "YES" << endl;
    return 0 ;
}

我是用了离线的方式做的,主要是当时没有想那么多,其实用在线的方式也是可以,而且更加简单

猜你喜欢

转载自blog.csdn.net/lewis_fehling/article/details/78628789