HDU 2897 (deformation of the classic game)

Source: Internet
Author: User

Encounter Mingxia
The Problem description encountered a month on the same day, so it became clear. 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 cannot exceed 100000 rows. Each row has three positive integers, N, P, and Q.
Output corresponds to each line of input. Based on 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
 
Source2009 multi-university training contest 10-host by nit

Solution:

This question is still applied to the core idea of the classic game theory, that is, a total of N, each value range is [p, q]. If two people play, you should take P, i'll get Q, you get p + 1, and I'll get a q-1 ....... the sum of p + q is always maintained in each round. Therefore, you can calculate the remainder of p + q. This idea is used. Of course, you can also use the SG function to extract the mandatory and mandatory states.

This question also has: if the number is less than P, it must be obtained. In fact, if the number is equal to P, it must also be obtained,

Determine whether N is <= P

Then P is subtracted and the remainder is obtained. However, if the result of the remainder is greater than Q, it cannot be obtained once.


Solution code:

#include <iostream>#include <cstdio>#include <vector>using namespace std;int n,p,q;void solve(){    if(n<=p){        printf("LOST\n");        return;    }    n=n-p;    if(n%(p+q)==0) printf("LOST\n");    else{        if(n%(p+q)<=q) printf("WIN\n");        else printf("LOST\n");    }}int main(){    while(scanf("%d%d%d",&n,&p,&q)!=EOF){        solve();    }    return 0;}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.