Codeforces 893A:Chess For Three(模拟)

题目链接:http://codeforces.com/problemset/problem/893/A

题意

Alex,Bob,Carl三人下棋,每次只能两个人进行下棋,要求输的那个人当旁观者,然后给出n个输赢情况,1代表Alex赢,2代表Bob赢,3代表Carl赢,判断给出的这n中情况是否符合事实

思路

模拟,因为第一场是Alex和Bob进行,所以设置三个变量,分别代表该场的胜者,败者和旁观者。每次结束对局,对胜者进行判定,看胜者是否是旁观者,如果不是,将败者和旁观者进行交换,否则,停止对局,输出“NO”

AC代码

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ull unsigned long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
#define lson o<<1
#define rson o<<1|1
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
int a[maxn];
void change(int a,int b)
{
	int t=a;
	a=b;
	b=t;
}
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	int n;
	int a1,a2,a3;
	a1=1;//win
	a2=2;//lose
	a3=3;//watch
	cin>>n;
	int flag=0;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
	{
		if(a[i]==a1)
		{
			int t=a2;
			a2=a3;
			a3=t;
		}
		else if(a[i]==a2)
		{
			int t=a1;
			a1=a3;
			a3=t;
		}
		else
		{
			flag++;
			break;
		}
	}
	if(flag)
		cout<<"NO"<<endl;
	else
		cout<<"YES"<<endl;
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值