• 博弈


    1.对称博弈
    Problem Description
    After hh has learned how to play Nim game, he begins to try another coin game which seems much easier.
    The game goes like this: 
    Two players start the game with a circle of n coins. 
    They take coins from the circle in turn and every time they could take 1~K continuous coins. 
    (imagining that ten coins numbered from 1 to 10 and K equal to 3, since 1 and 10 are continuous, you could take away the continuous 10 , 1 , 2 , but if 2 was taken away, you couldn't take 1, 3, 4, because 1 and 3 aren't continuous)
    The player who takes the last coin wins the game. 
    Suppose that those two players always take the best moves and never make mistakes. 
    Your job is to find out who will definitely win the game.
    Input
    The first line is a number T(1<=T<=100), represents the number of case. The next T blocks follow each indicates a case.
    Each case contains two integers N(3<=N<=109,1<=K<=10).
    Output
    For each case, output the number of case and the winner "first" or "second".(as shown in the sample output)
    问题描述在HH已经学会了如何玩NIM游戏,他beginstwo玩家开始游戏一圈n个硬币。
    他们轮流从圆硬币,每次他们可以采取1 K连续硬币。
    (想象十个硬币从1到10,K等于3,因为1和10是连续的,你可以拿走连续10, 1, 2,但是如果2被拿走了,你不能拿走1, 3, 4,因为1和3不是连续的)
    拿最后一枚硬币的运动员赢了这场比赛。
    假设那两个球员总是采取最好的行动,从不犯错误。
    你的工作是找出谁肯定会赢这场比赛。
    输入
    第一行是数字t(1 < = < = 100),表示实例数。接下来的t块跟随每个指示一个案例。
    每个案例包含两个整数N(3≤N≤109,1 <= k < = 10)。
    输出
    对于每种情况,输出案例数和获胜者“第一”或“第二”(如示例输出中所示)。
    Sample Input

    2 
    3 1 
    3 2


    Sample Output
    Case 1: first 
    Case 2: second
     对称博弈。
    一般都是圆啊方啊什么的。
    对于这道题而言,可以有三种情况:
    ①k等于1    一次最多只能拿1个(每堆只有一个),那就是看奇偶了。
    ②n≤k  这种情况,那肯定先拿的赢。
    ③ 这条就是对称博弈了, 除了上述两种情况外的情况(n>k && k!=1)
        这时候,无论你第一个人拿什么,怎么拿,后手的人完全可以在第一个人拿的对称的地方做同样的事情。
    这样,后手就一定会取得胜利,因为最后一步是后手走的。


    第三条自己在本上画一画就不难发现了。

    #include <stdio.h>  
    int main()  
    {  
        int t,i,n,k;  
        scanf("%d",&t);  
        for( i=1;i<=t;++i )  
        {  
            scanf("%d%d",&n,&k);  
            printf("Case %d: ",i);  
            if( k==1 )  
            {  
                if( n&1 )  
                    printf("first
    ");  
                else   
                    printf("second
    ");  
            }  
            else if( n<=k )
                printf("first
    ");  
            else    printf("second
    ");  
        }  
        return 0;  
    }

      
    环形博弈
    One day, zbybr is playing a game with blankcqk, here are the rules of the game:
    There is a circle of N stones, zbybr and blankcqk take turns taking the stones.
    Each time, one player can choose to take one stone or take two adjacent stones.
    You should notice that if there are 4 stones, and zbybr takes the 2nd, the 1st and 3rd stones are still not adjacent.
    The winner is the one who takes the last stone.
    Now, the game begins and zbybr moves first.
    If both of them will play with the best strategy, can you tell me who will win the game?
    输入
    The first line of input contains an integer T, indicating the number of test cases (T≈100000).
    For each case, there is a positive integer N (N ≤ 1018).
    输出
    Output the name of the winner.
    示例输入
    2
    1
    2
    示例输出
    zbybr
    zbybr
    题目大意:zbybr先手,谁将环形石子最后一个拿走谁赢
    对于环形的博弈,先手只可能在他能拿石子个数的范围内取胜,否则后手赢。因为当石子个数大于先手能拿的个数,若先手拿完后,剩下奇数个后手拿与先手对应位置的石子即可,为偶则拿对应的两个,总可以让先手输
     

    #include <stdio.h>
    #include <string.h>
    int main()
    {
        int t;
        long long int n;
        scanf("%d",&t);
            while(t--)
            {
                scanf("%lld",&n);
                if(n<3)
                    printf("zbybr
    ");
                else
                    printf("blankcqk
    ");
            }
        return 0;
    }
  • 相关阅读:
    数据结构(三)栈与递归
    机器学习(二)------ 回归
    数据结构(二)线性表
    数据结构(一)数据结构基础
    机器学习 (一)------分类
    操作系统概述
    NumPy函数库基础
    总线与输入输出子系统
    FT VIEW SE高效开发之全局对象
    STUDIO 5000 V32新CRACK和新功能
  • 原文地址:https://www.cnblogs.com/zcy19990813/p/9702838.html
Copyright © 2020-2023  润新知