zoukankan      html  css  js  c++  java
  • HDU 3389 Game (阶梯博弈)

    Game

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


    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
     

    题意:

      1-N带编号的盒子,当编号满足A>B && A非空 && (A + B) % 3 == 0 && (A + B) % 2 == 1则可以从A中取任意石头到B中.谁不能取了谁就输.

    思路: 其本质为阶梯博弈;

      阶梯博弈:博弈在一列阶梯上进行,每个阶梯上放着自然数个点,两个人进行阶梯博弈...      每一步则是将一个集体上的若干个点( >=1 )移到前面去,最后没有点可以移动的人输;

     在本题中 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; 那么他们的转移的步数的奇偶性也会确定;

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

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    
    using namespace std;
    
    int main(){
    
        //freopen("input.txt","r",stdin);
    
        int t,n,cases=0;
        scanf("%d",&t);
        while(t--){
            scanf("%d",&n);
            int ans=0,x;
            for(int i=1;i<=n;i++){
                scanf("%d",&x);
                if(i%6==0 || i%6==2 || i%6==5)
                    ans^=x;
            }
            printf("Case %d: ",++cases);
            if(ans!=0)
                puts("Alice");
            else
                puts("Bob");
        }
        return 0;
    }
  • 相关阅读:
    QPushButton设置背景图片,设置背景透明度
    QMessageBox 弹窗提示总结
    Qt中 QObject * sender() const的用法
    Java获取文件后缀
    Qt QLabel设置背景色
    Qt 设置程序图标
    程序猿 tensorflow 入门开发及人工智能实战
    Github + Hexo 搭建博客
    Linux常用命令
    深度学习路线记录
  • 原文地址:https://www.cnblogs.com/jackge/p/3232399.html
Copyright © 2011-2022 走看看