HDU 3389 Game(博弈 Nim 找规律)

Game

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


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



题意:
游戏规则就是把卡片移动到更靠左的盒子中,A B 两个盒子满足(A+B) % 3 == 0 并且满足A、B奇偶性质不同。

思路:

将每个盒子看作分开的石子堆,考察每一类盒子向左侧放卡片的策略。 发现最终卡片会被放到1、3、4三个盒子中,即最终结果。故经过奇数步骤到达这三个盒子中的必然是胜点,经过偶数步骤到达这些盒子的是必败情况。必败情况的SG函数值是0,对异或不会产生影响。

分情况  奇数:  %3 == 0 偶数步骤后到达盒子3

%3 == 1 偶数步骤后到达盒子1

%3 == 2 ji步骤后到达盒子2

偶数:  %3 == 0 奇数步骤后到达盒子3

%3 == 1 偶数步骤后到达盒子1

%3 == 2 奇数步骤后到达盒子4


偶数步骤到达最终结果的情况均可以忽略不计,剩下的情况可以想象成N多组尼姆游戏,不断异或即可得到答案。


#include <iostream>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;

int main()
{
	int casen, res, num, i, temp, countn = 1;
	scanf("%d", &casen);
	while(casen--){
		scanf("%d", &num);
		res = 0;
		for(i = 1; i <= num; i++){
			scanf("%d", &temp);
			if(i % 2 == 1)
				if(i % 3 == 2) res = res xor temp;
			if(i % 2 == 0){
				if(i % 3 == 2) res = res xor temp;
				if(i % 3 == 0) res = res xor temp;
			}
		}
		if(res != 0)
			printf("Case %d: Alice\n", countn++);
		else
			printf("Case %d: Bob\n", countn++);
	}
	
	return 0;
}


1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。、可私 6信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。、可 6私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。、可私 6信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值