hdu 2897 Encounter Mingxia

Variation 2 of the bash game: There are n stones in the initial state. Except for the last time, the number of items taken each time must be between [p, q]. The person who took the coin for the last time loses. (HDU 2897) 
The state of this question is a little more complicated, and the conditions for winning and losing are opposite to the previous ones. In general bash games, the number taken each time can be regarded as between [1, m], and the winning hand is judged as n % (1+ m) , so we can guess that the winning hand to take [p,q] is n % (p+q), and by verifying the conjecture, we can find the following strategy:

When n=k∗(p+q), the first move Take q for the first time, and in the subsequent rounds, if you take x in the second hand, and then take p+q−x in the first hand, then p + in the second hand will be left in the end, and the first hand wins.
When n=k∗(p+q)+s, it should be considered according to the situation: 
if s is between [1,p], take x first, then p+q−x can be taken in the second hand, and finally leave s for the first hand , the second hand wins;
if s is between (p,p+q), take any x (1≤s−x<p) in the first hand, y in the second hand, p+q−y in the first hand, and leave at the end If s - x are given to the second player, the first player wins;

#include<stdio.h>
using namespace std;

int main(){
	int n,p,q;
	while(scanf("%d%d%d",&n,&p,&q)!=EOF){
		int r = n%(p+q);
		if(r!=0&&r<=p)
		printf("LOST\n");
		else printf("WIN\n");
	}
	return 0;
}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325778660&siteId=291194637