Codeforces Round #721 (Div. 2) B2. Palindrome Game (hard version)

126 篇文章 0 订阅

题目:
题目链接:

题解:
先数出有多少个位置不匹配,如果为 0 0 0则和 B 1 B1 B1一样,如果为 1 1 1则alice第一轮翻转,bob必须得第一个填,如果0 的数量大于2则bob必败,不匹配位置大于1,则alice必胜

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		string a;
		cin>>a;
		int con=0;
		for(int i=0;i<n;i++)
		{
			if(a[i]=='0') con++;
		}
		int c=0;
		for(int i=0,j=n-1;i<j;i++,j--)
		{
			if(a[i]!=a[j]) c++;
		}
		if(c==0)
		{
			if(con%2==0)
			{
				cout<<"BOB"<<endl;
			}
			else if(con%2!=0)
			{
				if(con>1) cout<<"ALICE"<<endl;
				else cout<<"BOB"<<endl;
			}
	    }
	    else if(c==1)
	    {
	    	if(con==2) cout<<"DRAW"<<endl;
	    	else cout<<"ALICE"<<endl;
	    }
	    else cout<<"ALICE"<<endl;
	}
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值