Partitioning Game(博弈论-sg函数打表)

Partitioning Game(博弈论-sg函数打表)

judge:LightOJ-1214
Time limit 4000 ms
Memory limit 32768 kB
OS Linux

描述

Alice and Bob are playing a strange game. The rules of the game are:

  1. Initially there are n piles.

  2. A pile is formed by some cells.

  3. Alice starts the game and they alternate turns.
    LightOJ-1214

Input

LightOJ-1214

LightOJ-1214

Sample Input

3
1
4
3
1 2 3
1
7

Sample Output

Case 1: Bob
Case 2: Alice
Case 3: Bob

题意

有n堆石子,每回合可选择把其中一堆分成 数量不同 的两堆,且必须分一次。不能再分的玩家输。

sg函数打表。

代码
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 1e3+5;
const int mod = 1e9+7;
const int maxn = 10005;
int sg[maxn], mex[maxn];

void getsg() {
	sg[0] = sg[1] = sg[2] = 0;
	for(int i = 3; i <= 10000; i++){
		memset(mex, 0, sizeof(mex));
		for(int j = 1; j * 2 < i; j++){
			mex[sg[j] ^ sg[i - j]] = 1;
		}
		int pos = 0;
		while(mex[pos] != 0) pos++;
		sg[i] = pos;
	}
}
 
int main() {
	//freopen("in.txt", "r", stdin);
	getsg();
	int t, n;
	cin >> t;
	int k = 0;
	while(t --) {
		cin >> n;
		int x;
		int ans;
		for(int i = 1; i <= n; ++ i) {
			cin >> x;
			if(i == 1)
				ans = sg[x];
			else
				ans ^= sg[x];
		}
		printf("Case %d: ", ++ k);
		if(ans)
			cout << "Alice" << endl;
		else
			cout << "Bob" << endl;
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值