[NYOJ] [833] Stone Game (VII)

Problem Description

取石子(七)
Time limit: 1000 msMemory limit: 64 MB

Description

Yougth and Hrdv play a game. They take n stones and arrange them in a circle. Yougth and Hrdv take stones from it in turn; whoever takes the last one wins. On each turn, a player may take one stone or two adjacent stones. Hrdv goes first. Output the winner’s name.

Input

Input contains multiple test cases.
Each test case contains one n, guaranteed to be within the int range.

Output

Output the winner’s name.

Sample Input

1
2
2
3

Sample Output

1
2
Hrdv
Yougth

Problem Analysis

The difference from normal stone taking is
that although each turn allows taking one or two
the two taken must be adjacent
and the stones initially form a circle
so the second player can “split” the stones
to prevent the first player from taking two at the key point

image.png

If the first player takes 1
then the second player takes 4
then the first player can only take 2 or 3
so the second player takes the other one and wins

The same reasoning extends to more stones
as long as the second player cuts the stones into two parts
the second player can win

So except when n is 1 or 2, where the first player wins directly
the second player can win in all other cases

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#include<stdio.h>
int main() {
	int n;
	while(scanf("%d",&n)!=EOF) {
		if(n>2)
			printf("Yougth\n");
		else
			printf("Hrdv\n");
	}
	return 0;
}

Problem address: NYOJ 833 Stone Taking (Seven)

Loading...