Encounter (Bashi Game + hdu2897), hdu2897
H- MingTime Limit:1000 MSMemory Limit:32768KB64bit IO Format:% I64d & % I64uSubmit Status Practice HDU 2897
Description
On that day, we met the next month. When I met you, I became a companion.
On that day, the sun and the moon met and I met you. Moreover, if the earth loses its glory, will you and I become friends? This is doomed to be a beautiful story. (The above is nonsense)
Like all secular people, Mr. t looks forward to the rare eclipse of a hundred years. Stop on the street to see the day, see the day and the month approaching, the Little t's neck is sour (he insisted that this posture has been more than half an hour ). He looked up and looked around. Suddenly I found a pretty mm standing around me. Gradually, this mm is so dazzling on this street. Is she an angel? The angel standing around t.
T shouted to mm: "Fate ~~". Mm is unambiguous: "Yes, we met in 500 !" (5000 words later ....)
John asked mm for contact information, but mm said, "I am playing a game with you. If you win, I will tell you my mobile phone number ." T, I thought that there would be a problem in the world that could beat me down, so I agreed. Mm started to talk about the game rules: "I have a pile of coins, a total of seven. I have taken coins from this coin heap. I have two or more coins at a time, if there are less than two items left, it will be taken once. I took turns with you until the coins in the heap were taken, and the last coin was counted and lost. I have played this game many times, so let you get it first ~"
T refers to a computation. No, is this an impossible task. Little t smiled proudly: "mm is preferred, haha ~" Mm was stunned at the hour. I thought it was an unexpected response to the small t.
But she is not angry: "Good boy, it's pretty clever. Otherwise, you give me my mailbox and I will send you a text, each line has three numbers n, p, q, indicates that a pile of coins have a total of n coins. Take the coins from this coin heap. Take at least p coins at a time, and obtain a maximum of q coins. If there are less than p coins, you need to get them all at once. The two take the coins in turn until the coins in the heap are taken, and the last coin is counted and lost. For the three numbers in each row, whether the first person has a winning strategy is given. If there is a WIN, otherwise the LOST is answered. You can send me the corresponding answer. If you can send me the correct answer before this evening, maybe we can see you tomorrow afternoon ."
T gave his email address to mm. When he is eager to go home and check his mailbox online, wow! Mm's email has arrived. He found that the text is up to 100000 rows, and the three numbers in each line are large, but they are all integers up to 65536. It's already six o'clock P.M. In the table. It seems impossible to manually calculate all the results. Can you help him and let him see the mm again?
Input
No more than 100000 rows. Each row has three positive integers, n, p, and q.
Output
Corresponding to each line of input, according to the game rules described above, determine whether the first accessor has a winning strategy. Output WIN or LOST.
Sample Input
7 2 46 2 4
Sample Output
LOSTWIN
A classic review introduces the following concepts:
Bash Game ):There are only one pile of n items, and two people take things from the pile of items in turn, each time at least one, a maximum of m. The final winner wins.
Obviously, if n = m + 1, a maximum of m items can be taken at a time. Therefore, no matter how many items are taken by the first accessor, the latter can take the remaining items at a time, the latter wins. Therefore, we discovered the rule of How to Win: If n = (m + 1) r + s, (r is an arbitrary natural number, s ≤ m ), the first accessors must take s items. If the second accessors take k (≤ m) items, the first accessors take m + 1-k items, and the result is (m + 1) (r-1), and later to maintain such a method, then the first accessors certainly win. In short, we need to leave a multiple (m + 1) to the opponent to win.
This question is the transformation of the Bashi game: take [p, q]. When it is less than p, the next time it is all taken. The last time the number is lost!
The analysis is similar to the preceding analysis. If n = (p + q) + k, (0 <k <= p), a maximum of q and a minimum of p are obtained each time. <Note: when n = 0, it is N points>
So... If (n-1) % (p + q) <p) printf ("LOST \ n ");
For example, [3, 6]
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 20 21 22
N P N
That's all.
Reprinted, please specify the Source: search for & STAR kids
Question link: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 2897
#include<stdio.h>int main(){ int n,p,q; while(scanf("%d%d%d",&n,&p,&q)!=EOF) { if(n==0) printf("WIN\n"); else if((n-1)%(p+q)<p) printf("LOST\n"); else printf("WIN\n"); } return 0;}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.