HDU 3389 Game(nim博弈)
来源:互联网 发布:蜂窝移动数据只有两个 编辑:程序博客网 时间:2024/06/05 06:01
Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 54 Accepted Submission(s): 48Problem 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
221 271 3 3 2 2 1 2
Sample Output
Case 1: AliceCase 2: Bob
Author
hanshuai@whu
Source
The 5th Guangting Cup Central China Invitational Programming Contest
Recommend
notonlysuccess
//1、3、4点不可再移动,1、3、4点为终点。//打表发现规律,x % 6 == 2 || 5 || 0 的数到达1、3、4点一定是通过奇数步。//其他的点,一定要先走到奇数步的点,才能到达1、3、4点。//偶数步的点不会影响结果//这就好像nim博弈取石子那样了,所以对奇数步的点,进行异或求解就好了#include <iostream>#include <string.h>#include <stdio.h>#include <algorithm>#include <queue>using namespace std;int main() { int t; cin >> t; for (int i = 1; i <= t; ++i) { int ans = 0; int n; cin >> n; for (int j = 1; j <= n; ++j) { int a; cin >> a; if (j % 6 == 2 || j % 6 == 5 || j % 6 == 0) { ans ^= a; } } if (ans) { cout << "Case " << i << ": Alice\n"; } else { cout << "Case " << i << ": Bob\n"; } }}
阅读全文
0 0
- HDU 3389 Game(nim博弈)
- HDU 3389 Game(博弈 Nim 找规律)
- HDU 3389 Game(博弈 Nim 找规律)
- HDU 5011 Game(Nim博弈)
- hdu 1730 Northcott Game (Nim博弈)
- HDU 5011 Game nim博弈
- HDU 5011 Game 【Nim博弈】
- hdu 1851 A Simple Game (Nim博弈)
- HDU 1730 Northcott Game(Nim博弈变形)
- HDU5011 Game(Nim博弈)
- Matrix Game (Nim博弈)
- HDU5011 Game(Nim博弈)
- Northcott Game (Nim博弈)
- hdu 1730 Northcott Game (nim博弈变形)
- HDU 1730 Northcott Game(nim博弈)
- hdu 1730 Northcott Game Nim博弈~~
- HDU 5011Game-多个堆的NIM博弈
- HDU 3915 Game NIM博弈 XOR高斯消元
- 线性可分与线性不可分
- 1324: 小周的烦恼
- JAVA中主数据类型的过载问题
- Java 面向切面编程(Aspect Oriented Programming,AOP)
- ubuntu 10.10不再提供支持后的source list 更新
- HDU 3389 Game(nim博弈)
- 使用 Adobe Acrobat 裁剪 PDF 白边及其他操作
- Build & Install GCC4.6.3 in CentOS (5.2 & 6.3)
- linux 修改IP
- Java中System类
- Linux C 文件操作
- Netty线程模型
- 金融风控-->客户流失预警模型-->金融数据分析
- 【Spring】Spring整合Struts2