HDU 3951 Coin Game(简单博弈,找找规律啦)

                                             Coin Game

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


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<=10 9,1<=K<=10).
 

Output
For each case, output the number of case and the winner "first" or "second".(as shown in the sample output)
 

Sample Input
 
  
2 3 1 3 2
 

Sample Output
 
  
Case 1: first Case 2: second
 
//方法:我是从(3 1)、(3 2)【3以后的都不用看了,因为后面m >= n了,first一次性拿完】
//然后从(4 1)、(4 2)、(4 3)【后面first赢】
//然后是(5 1)、(5 2)、(5 3)、(5 4)【后面first赢】自此我就发现只要是first先手,且非m==1的情况,second总能使得等first第一次拿完后,他再拿
//与first对称的那一部分,这样把这个圈分割成了不连续两部分,这样被分割的两部分让first先拿,second就可以照着first拿的模式,对称地在不同的部分那相同模式;
//反正是对称的两部分first先拿,总会留下另一部分给second拿,这样second就会是最后一个拿完的;
//(n 1)的情况,即m==1时,每次只能拿一个,看总个数n是奇数还是偶数不就可以了,而且还没有拿的要求,反正n确定谁赢就定了.
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
using namespace std;

int main(){
    int t;
    int n, m;
    int cas = 1;
    cin >> t;
    while(t--){
        scanf("%d%d", &n, &m);
        if(n <= m){
            printf("Case %d: first\n", cas++);
        }
        else if(m == 1 && n % 2==1){
            printf("Case %d: first\n", cas++);
        }
        else
            printf("Case %d: second\n", cas++);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/guihaiyuan123/article/details/80141496