(SG博弈)uva 10561 - Treblecross

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=477&problem=1502&mosmsg=Submission+received+with+ID+15934726


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#define mem(x,i)	memset(x,i,sizeof(x))
#define sf1(a)		scanf("%d", &a)  
#define sf2(a,b)	scanf("%d %d", &a, &b)  
#define sf3(a,b,c)	scanf("%d %d %d", &a, &b, &c)  
#define sf			scanf
#define pf			printf 
const double EPS = 1e-10;
const double pai = acos(-1.0);
const int INF = 0xfffffff;
const int MOD = 1000000007;
typedef long long LL;
const int maxn = 205;

int g[maxn];
char a[maxn];
int mex(set<int> &s){
	set<int>::iterator it = s.begin();
	for (int i = 0; it != s.end(); it++, i++)
	if (*it != i)
		return i;
	return s.size();
}
void GetSG(){
	g[0] = 0; g[1] = g[2] = g[3] = 1;
	for (int x = 4; x < maxn; x++){
		set<int> s;
		for (int j = 3; x - j >= 0; j++){
			if (j <= 5)
				s.insert(g[x - j]);
			else if (j > 5)
				s.insert(g[j - 5] ^ g[x - j]);
		}
		g[x] = mex(s);
	}
}
bool judge(char *a){
	int len = strlen(a);
	for (int i = 0; i < len; i++){
		if (i + 2 < len&&a[i] == 'X'&&a[i + 1] == 'X'&&a[i + 2] == 'X')
			return false;
	}
	for (int i = 0; i < len; i++){
		if ((i + 1 < len&&a[i] == 'X'&&a[i + 1] == 'X') || (i + 2 < len&&a[i] == 'X'&&a[i + 2] == 'X'))
			return true;
	}

	char b[maxn];
	strcpy(b, a);
	for (int i = 0; i < len; i++){
		if (a[i] == 'X'){
			if (0 <= i - 1 && i - 1 < len)	b[i - 1] = 'X';
			if (0 <= i - 2 && i - 2 < len)	b[i - 2] = 'X';
			if (0 <= i + 1 && i + 1 < len)	b[i + 1] = 'X';
			if (0 <= i + 2 && i + 2 < len)	b[i + 2] = 'X';
		}
	}
	int cnt = 0;
	vector<int> s;
	for (int i = 0; i < len; i++){
		if (b[i] == 'X'){
			s.push_back(cnt);
			cnt = 0;
		}
		else if (b[i] == '.')
			cnt++;

		if (i == len - 1)	s.push_back(cnt);
	}
	int ret = 0;
	for (int i = 0; i < s.size(); i++)
		ret ^= g[s[i]];
	return ret != 0;
}
int main()
{
	//freopen("f:\\input1.txt", "r", stdin);
	GetSG();
	int T;
	sf1(T);
	while (T--){
		sf("%s", a);
		if (judge(a)){
			pf("WINNING\n");
			vector<int> ans;
			for (int i = 0; i < strlen(a); i++){
				if (a[i] == '.'){
					a[i] = 'X';
					if (judge(a) == false)	ans.push_back(i + 1);
					a[i] = '.';
				}
			}
			for (int i = 0; i < ans.size(); i++)
				pf("%d%s", ans[i], i == ans.size() - 1 ? "\n" : " ");
		}
		else pf("LOSING\n\n");
	}
	return 0;
}
/*
4
.....
X.....X..X.............X....X..X
.X.X...X
...............................................


WINNING
3
LOSING
WINNING
3
WINNING
1 12 15 17 20 24 28 31 33 36 47
*/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值