A - Ervin and Joker (简单博弈)

A - Ervin and Joker
Ervin and Joker are playing a game with rocks.
Initially, there are N rocks, indexed from 1 to N. In one move, the player chooses at least 1
and at most K consecutively indexed rocks (all of them should not have been removed) and removes them from the game.Ervin always starts the game, and then Ervin and Joker take turns making moves. The player who is unable to make a move (because all rocks are removed) loses.
Given N,K, find who is going to win the game (assuming they are smart and are playing optimally).

Input
The first line contains two integers N,K(0≤N≤106,1≤K≤106)
Output
Print a name (“Ervin” or “Joker”, without the quotes) — the person who is going to win the game.

Examples
Input
1 1
Output
Ervin
Input
9 3
Output
Ervin

思路:
显然,只要Ervin能把中间的一个或者两个拿走使之隔开,那么就能形成“复读机”局势,那么Ervin必胜。

显然,Joker获胜的情况只有以下两种:

#include "stdio.h"
int main()
{
    int n, k;
    scanf("%d %d",&n,&k);
    if(n == 0)
    {
        printf("Joker\n");
    }
    else if(k == 1)
    {
        if(n % 2 == 0)
        {
            printf("Joker\n");
        }
        else
            
        {
            printf("Ervin\n");
        }
        
    }
    else
    {
        printf("Ervin\n");
    }
    return  0;
}

你可能感兴趣的:(错题本)