博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 3389 Game (阶梯博弈)
阅读量:4588 次
发布时间:2019-06-09

本文共 2206 字,大约阅读时间需要 7 分钟。

Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u

 

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
 

Source

The 5th Guangting Cup Central China Invitational Programming Contest
题意:有t组数据。每组数据有n个盒子,这n个盒子编号为12345678......。
(注意不是从0开始的)
   每个盒子中有一定量的卡片。每次取编号为B和编号为A的盒子, 要求满足
   
B<A && (A+B)%2=1 && (A+B)%3=0,把A中的任意数量的卡片转移给B,
谁不能再转移了谁输。
题解:阶梯博弈,只需要考虑步数为奇数的盒子,步数为偶数的盒子不需要考虑。
   在本题中编号为1,3,4的盒子不能转移卡片,其余盒子均可转移。例如:
   
2->1,   5->4,   6->3,   7->2   ,8->1,   9->6...
   其本质为有n级阶梯,我们在%3的余数中进行转移0->0,   1->2,   2->1;
最后的结果
   一定是1或者3或者4,这些盒子中卡片转移的步数的奇偶性是一定的。为什么这么说呢?
   因为即使有些盒子例如编号11的盒子,有11->4和11->10->8->1两种选择,但是这
   两种选择的步数的奇偶性是相同的,都是奇数,所以奇偶性是一定的。
   所以我们把这个阶梯博弈转化为尼姆博弈就行了,
对步数为奇数的盒子进行尼姆博弈
   在纸上多写几个数或者用打表的方法可以发现如下规律:
   
盒子编号模6为0,2,5的位置的移动步数为奇,其余为偶。
   推到这里就很好实现了。
#include 
#include
using namespace std;int main(){ int t,cas=1; cin>>t; while(t--) { int n,data,ans=0; cin>>n; for(int i=1;i<=n;i++) { cin>>data; if(i%6==2||i%6==5||i%6==0) ans^=data; } if(ans) printf("Case %d: Alice\n",cas++); else printf("Case %d: Bob\n",cas++); } return 0;}

 

转载于:https://www.cnblogs.com/Ritchie/p/5624327.html

你可能感兴趣的文章
笨方法学Python3(21-44)
查看>>
笨方法学python3
查看>>
Linux for Matlab中文注释乱码(亲测有效)
查看>>
RK3399Pro Android Rock-X 人工智能开发系列(1)
查看>>
RK3399Pro Android Rock-X 人工智能开发系列(2)
查看>>
pxe批量装机
查看>>
linux典型应用对系统资源使用的特点
查看>>
linux性能分析工具Procs
查看>>
linux性能分析工具Vmstat
查看>>
linux性能分析工具Memory
查看>>
linux性能分析工具Uptime
查看>>
linux性能分析工具Cpu
查看>>
linux性能分析工具Ntop
查看>>
linux性能分析工具Sysstat
查看>>
linux改变内核参数
查看>>
Linux系统平台调优
查看>>
linux内存子系统调优
查看>>
Linux内核的arch目录
查看>>
配置Linux内核
查看>>
Linux常用配置选项
查看>>