A. Chess For Three

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.

input


output

YES

思路:简单的模拟即可。

AC代码:

 #include<bits/stdc++.h>

 using namespace std;
int main(){
int _;
cin>>_;
int flag=;
int arr[_+];
int a,b,c;
a=;b=;c=;
for(int i=;i<=_;i++){
cin>>arr[i];
if(arr[i]==c){
flag=;
}
if(flag){
if(arr[i]==a){
swap(b,c);
}else if(arr[i]==b){
swap(a,c);
}else if(arr[i]==c){
swap(a,b);
}
}
}
if(flag){
puts("YES");
}else{
puts("NO");
}
return ;
}

最新文章

  1. .Net配置中心-服务端/客户端
  2. HTTP协议学习---(七)代理
  3. java线程的理解
  4. HTML常用标签及其全称
  5. XML的xPath格式
  6. 如何使用 AngularJS 的 ngShow 和 ngHide
  7. JTable 的使用
  8. VS编辑器主题变换插件-EasyVS
  9. 模仿ICE的structured panorama小按钮
  10. JavaScript DOM编程艺术读后感(1)—— 平稳退化
  11. Java 内存模型- Java Memory Model
  12. C#学习笔记-状态模式
  13. 新版Azure CDN HTTPS加速服务正式上线
  14. mysql的必知技巧
  15. ANG通证是什么?有关ANG通证的干货都在这里
  16. [USACO07JAN]Cow School
  17. chrome自动填表会遮挡input中背景图的问题解决方法
  18. 20175314 实验一 Java开发环境的熟悉
  19. C语言运算符优先级和ASCII表
  20. php的ajax简单实例

热门文章

  1. Win7 Eclipse 搭建spark java1.8(lambda)环境:WordCount helloworld例子
  2. docker服务端与客户端通信方式
  3. 用Lua的协程实现类似Unity协程的语句块
  4. 怎样理解 display:none 和 visibility:hidden
  5. git基本操作及实用工具
  6. seaborn:一个更强大的画图工具
  7. css3之媒体查询
  8. struts-2.5.14.1中jar包引入
  9. git 常用命令操作
  10. jmeter连接mysql数据库进行多条语句查询