zoukankan      html  css  js  c++  java
  • HDU 3389 GAME

    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

    分析

    • 把每堆石子按照对(6)取模分成(6)种情况,那么所有的操作都会发生在(1-2,0-3,4-5)之间
    • 再加以分析可以发现在很多次操作之后,编号为1,3,4的石子堆不能移动到其他堆上,并且此时其他所有堆上的石子数都可以达到0
      • 考虑模(6)得到0,2,4的所有石子堆,在终态时他们的抑或和为(0)。在游戏进行中,如果0,2,4对应的石子堆抑或和不为(0),那么类似于NIM博弈,我们完全可以通过操作使得他们的抑或和为(0)
      • 而对于0,2,4对应石子堆抑或和为(0)的状态,不管怎么操作,石子堆的抑或和都会变成非(0)数。
      • 所以以上第一种状态为必胜态,第二种为必败态

    代码

    展开 ```cpp #include #include #include #include #include using namespace std; int main(int argc, char const *argv[]) { int t,Case=1; scanf("%d", &t); while(t--){ int n; scanf("%d", &n); int x,sum=0; for (int i = 1; i <= n; ++i) { scanf("%d", &x); if(i%6==0||i%6==2||i%6==5) sum^=x; } printf("Case %d: %s ", Case++,sum?"Alice":"Bob"); } return 0; } ```
  • 相关阅读:
    border-radius属性失效了Ծ‸Ծ
    Python默认版本切换
    Mac系统下安装PyCharm
    Python查看与安装
    MySql查询最近一个月,一周,一天
    Mysql计算并保留两位小数
    Mysql 用户ip访问根据省份查询
    Echarts 中国地图(包括china.js文件)
    JQuery进度条
    Java 求两个数百分比%
  • 原文地址:https://www.cnblogs.com/sciorz/p/8962854.html
Copyright © 2011-2022 走看看