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

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

     Status

    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 <iostream>
    #include <cstdio>
    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
    ",cas++);
            else
            printf("Case %d: Bob
    ",cas++);
        }
        return 0;
    }
  • 相关阅读:
    日本自然科学研究机构生理学研究所:研究显示古典音乐有助治疗突发性耳聋(转)
    苹果新专利:视频通话不怕掉帧(转)
    三步解决EntityFramework Code First中的MissingMethodException错误
    Unity3D去掉全屏时的屏幕黑边
    WindowsPhone-GameBoy模拟器开发六--[转]指令系统实现必读:补码
    WindowsPhone-GameBoy模拟器开发五--使用XNA初略实现Gameboy显示系统
    WindowsPhone-GameBoy模拟器开发四--Gameboy显示系统分析
    python继承初始化对象实例时 TypeError: module() takes at most 2 arguments (3 given)
    python __getattr__和__getattribute__ 区别
    python – 将列表拆分为较小的列表
  • 原文地址:https://www.cnblogs.com/Ritchie/p/5624327.html
Copyright © 2011-2022 走看看