hdu 3389 Game (阶梯博弈)

Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 703    Accepted Submission(s): 495


Problem Description
Bob and Alice are playing a new game. There are n boxes which have been numbered from 1 to n. Each box is either empty or contains several cards. Bob and Alice move the cards in turn. In each turn the corresponding player should choose a non-empty box A and choose another box B that B<A && (A+B)%2=1 && (A+B)%3=0. Then, take an arbitrary number (but not zero) of cards from box A to box B. The last one who can do a legal move wins. Alice is the first player. Please predict who will win the game.
 

Input
The first line contains an integer T (T<=100) indicating the number of test cases. The first line of each test case contains an integer n (1<=n<=10000). The second line has n integers which will not be bigger than 100. The i-th integer indicates the number of cards in the i-th box.
 

Output
For each test case, print the case number and the winner's name in a single line. Follow the format of the sample output.
 

Sample Input
  
  
2 2 1 2 7 1 3 3 2 2 1 2
 

Sample Output
  
  
Case 1: Alice Case 2: Bob
 

Author
hanshuai@whu
 

Source
 

Recommend
notonlysuccess
 

Statistic |  Submit |  Discuss | Note

题解:阶梯博弈

在本题中 1,3,4 的状态不能转移到其他状态; 其他每个状态皆可转移; 且位置特定

其本质我们有N级阶梯,现在要在 %3 的余数间转移, 0->0, 1->2, 2->1; 其最后的结果为1, 3, 4; 那么他们的转移的步数的奇偶性也会确定;

我们只要选择步数为奇数的位置做nim博弈就行了;而可以通过打表归纳证明得出模6为0、2、5的位置移动步数为奇,其余为偶;

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1003
using namespace std;
int n,m,a[N];
int main()
{
	scanf("%d",&m);
	for (int j=1;j<=m;j++){
		scanf("%d",&n); int ans=0;
		for (int i=1;i<=n;i++) {
			int x; scanf("%d",&x);
			int t=i%6;
			if (t==0||t==2||t==5) ans^=x;
		}
		printf("Case %d: ",j);
		if (ans) printf("Alice\n");
		else printf("Bob\n");
	}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值