题解 CF1527B1【Palindrome Game (easy version)】

概述

题号 难度 \(AC\)时间及记录
\(\texttt{CF1527B1}\) \(\texttt{洛谷难度:暂无评定}\) \(\texttt{On 2021/05/22}\)

解析

这道题目题目意思不难理解,
我们关注题目中给出了一个性质:给入的字符串回文。
那么我们可以这样考虑:
(如果刚开始就全部是 \(1\),那么是 \(DRAW\)。)
否则,每一次 \(ALICE\) 取走一个 \(0\)\(BOB\) 就可以取走和他对称的一个 \(0\)
直到只剩最后两个 \(0\),此时他们的花费是一样的。
\(ALICE\) 取走了倒数第二个 \(0\),这时 \(BOB\)将字符串反转即可获胜。
但是如果串串的长度是奇数,就要特判一下中间那个。

#include<bits/stdc++.h>
#define BetterIO ios::sync_with_stdio(false)
using namespace std;
int N;
string S;
int Array[1001],Count;
int main(void)
{
	BetterIO;
	#ifndef ONLINE_JUDGE
	freopen("SampleIN.in","r",stdin);
	#endif
	register int Case;cin>>Case;
	while(Case--)
	{
		register int i;cin>>N;
		Count=0;cin>>S;
		for(i=0;i<N;i++)Array[i+1]=S[i]-'0';
		register int Flag=0;
		for(i=1;i<=N;i++)if(!Array[i])Flag++;
		if(!Flag)cout<<"DRAW"<<endl;
		else
		{
			if(N&1)
			{
				if(Array[N/2+1]||Flag==1)cout<<"BOB"<<endl;
				else cout<<"ALICE"<<endl;
			}
			else cout<<"BOB"<<endl;
		}
	}
	return 0;
}
posted @ 2021-05-24 14:53  Bushuai_Tang  阅读(135)  评论(0编辑  收藏  举报