跳到正文

题解

【这是我做过最简单的博弈论】 UVA11489 题解

RainRecall约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年3月13日
篇幅
约 1 分钟
题目
UVA11489

版本

  1. v1当前

首先求出每一位对 33 取模的余数,然后求出先手要去掉什么数。

设这个数为 xx,则看一下余数中是否存在 x mod 3x\bmod 3,如果没有先手必输。

否则删掉 xx 后,剩下的一定只能通过删余数为 00 的数来满足条件,所以如果余数为 00 的数的数量为奇数,先手必输。否则先手必胜。

时间复杂度 O(T∣s∣)O(T|s|)。

AC code

C++
#include<iostream>
using namespace std;
int T,a[4];
string s;
int main(){
	cin>>T;
	for(int c=1;c<=T;++c){
		a[0]=a[1]=a[2]=0;
		cin>>s;
		int l=s.size();
		for(int i=0;i<l;++i){
			a[(s[i]-'0')%3]++;//求出余数
		}
		int qwq=(a[1]+a[2]*2)%3;
		a[qwq]--;
		cout<<"Case "<<c<<": ";
		if(a[qwq]<0||a[0]&1)cout<<"T\n";
		else cout<<"S\n";
	}
	return 0;
}
原文