893AChess For Three
来源:互联网 发布:卫浴行业数据 编辑:程序博客网 时间:2024/06/07 05:09
模拟
题意
三个人下棋,每次两个人下,赢的人和第三个人下棋。,每次记录赢的那个人。
第一次只能第一个alex和Bob下,他们其中一个胜利的人,然后和carl下,我们就用carl替换输掉bob,每次用看比赛的人替换掉输掉的那个人。
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
Note
In the first example the possible situation is:
Alex wins, Carl starts playing instead of Bob;
Alex wins, Bob replaces Carl;
Bob wins.
The situation in the second example is impossible because Bob loses the first game, so he cannot win the second one.
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;int main(){ int n,a,b,c,temp,q[110]; int flag; while(cin>>n) { for(int i=0; i<n; i++) cin>>q[i]; a=1,b=2,c=3; for(int i=0; i<n; i++) { flag=0; if(q[i]==a||q[i]==b) { if(q[i]==a) { temp=b; b=c; c=temp; } if(q[i]==b) { temp=a; a=c; c=temp; } flag=1; } if(!flag) break; } if(!flag) puts("NO"); else puts("YES"); } return 0;}
- 893AChess For Three
- Codeforces Edu 33 A 893AChess For Three
- CodeForces 893A Chess For Three
- Three Algorithms for Fibonacci
- cfA. Chess For Three
- chess for three A
- A. Chess For Three
- Codeforce 893A Chess For Three (模拟)
- Three way for Binding Application
- check target for three times
- Three Optimization Tips for C++
- codeforces893A chess for three题解
- Educational Codeforces Round 33 (Rated for Div. 2) 893A. Chess For Three
- Attend BorCon 2004 for LESS - Take Three!
- Three Rules for Effective Exception Handling(英文)
- Three Rules for Effective Exception Handling(中文)
- Three Rules for Effective Exception Handling
- Three Rules for Effective Exception Handling(中文)
- Windows 右键菜单打开MSYS-MinGW
- java项目(包含外部jar)打包
- 2.canvas绘制网格以及坐标轴
- json 简介
- newrelic的android sdk实现原理解析
- 893AChess For Three
- bzoj 3158: 千钧一发 最小割
- angular2基础/高级
- 进程和线程的区别
- 关于DIV相对于父DIV绝对定位
- 分治技巧在高级数据结构中的应用——cdq分治(一)&&bzoj3262例题详解
- python中数据聚合与分组运算
- 游戏服务器的常用架构
- Python Review