E-Nana in Wonderland Series--inexplicable episode

Source: Internet
Author: User
Tags greatest common divisor

E - Nana in Wonderland Series--inexplicable episode Time Limit: 2000/1000ms (java/others) Memory Limit: 128000/64000kb (java/others) Problem Description

Nana because to help peach blossom villagers solve a big problem and by the villagers respect, but because Nana still want to continue to explore this magical world, had to reluctantly and villagers farewell. When Nana left the village, Nana lost her memory! She did not remember all the peach Blossom Village, she did not remember to eat a lot of sweets, she did not remember her to go to the lake and jump for a long while, even her own name do not remember! Nana wandered blindly around, suddenly came to a Prince Charming, he asked: "Are you Alice?" ”。 Nana thought, "Alice?" Well-cooked name, is this my name? "and answered:" Yes. May I ask what you are? "Prince Charming is happy to say:" My name is Bob, I find you for a lifetime, without you, I am always forgotten by the father, we go back to the palace! The Yu Shinana was taken to the palace in a daze.

King: "Are you Alice?" What do you think? 3rd, you become dementia, ah, you and my son Bob first play a game, I see if you have a brain problem. Nana had to play the game with Bob in order to prove her mind was fine.

The rules of the game are very simple, there is a collection at the beginning, there are n different numbers in the collection, and Alice (Nana) and Bob take turns to operate, each can choose two number A, B, may wish to set a>b, but requires a-a not in the collection, a-B into the collection. If it's someone's turn and can't do anything, the person loses the game. As a professional game player, Nana can use the body's intuition to carry out optimal operation even if she loses her memory. Then ask, when Alice (Nana) and Bob all along the optimal strategy, the woman first (that is, Nana), who will win in the end?

Input

Multiple sets of data, first a positive integer t (t<=20), representing the number of groups of data

For each set of data, the first is an integer n (1<=n<=1,000), followed by n integers x[i] (0<x[i]<=1,000,000,000), which represents the collection. Ensure that the collection elements do not appear the same.

Output

For each set of data, if Alice (Nana) finally wins, output "win"

If Bob finally wins, output "lose"

If the outcome cannot be separated, the output "Draw", (both do not include double quotes, pay attention to case, recommended copy)

Sample Input
251 2 3 4 551 2 3 4 6
Sample Output
Losewin
Hint

Example 1, at the beginning regardless of Nana chooses which two elements, the difference is included in the collection, so Nana can not operate, Bob Victory, output lose

Example 2, the first Nana can only choose 1 and 6 of these two elements, and put 6-1=5 into the collection, then the collection becomes 1,2,3,4,5,6 Bob cannot operate, Alice (Nana) win, output win

Test instructions: There is a set of n elements, two people take turns pick two number, must meet two number of the difference is not in the set, and then put the difference of two number into the set, can not be manipulated by the author negative

Solution: We notice that each put in the collection is a difference of two, so the greatest common divisor of the set is kept constant, that is to say, all the numbers in the set can be expressed as a set of greatest common divisor integer times, (recall the method of calculation greatest common divisor, and constantly make difference for poor, greatest common divisor remains unchanged). You can set this greatest common divisor is D, then this game will be a victory or not? The answer is yes, because this operation does not add a larger number to the collection-it always adds a small number, and the terminating condition must be that all the numbers in the collection are exactly {d,2d,3d,......, X[max]}, where X[max] is the maximum number in the collection. So how many numbers are there in the final set? X[MAX]/D, from the beginning there are n that this game will carry X[max]/d-n round, the last round is who, who loses. So just judge the parity of x[max]/d-n.

Node: The solution to speak almost, is to beg greatest common divisor time, originally I did not judge M==1, is completely traverse over again, with 372MS, added after became 0MS. There is also a way to loop n times, initialize the number of conventions to the first number, then each and the next number of conventions, and then replace the number of conventions, but also to 1 end judgment GCD, this should be more simple.

1#include <stdio.h>2#include <string.h>3   4 intgcdintAintb)5 {6     if(b!=0)returnGCD (b,a%b);7     Else returnA;8 }9   Ten intMain () One { A     intt,n,i,j,x[1003],g,m,ma; -      while(SCANF ("%d", &t) = =1) -     { the          while(t--) -         { -scanf"%d",&n); -G=ma=0; +              for(i=0; i<n;i++) -             { +scanf"%d",&x[i]); A                 if(ma<X[i]) atMa=X[i]; -             } -              for(i=0; i<n;i++) -             { -                  for(j=i+1; j<n;j++) -                 { inm=gcd (X[i],x[j]); -                     if(g==0|| G>m) tog=m; +                     if(m==1) Break; When the number of conventions is 1, there is no need to continue to find, already the smallest -                 } the                 if(m==1) Break; *             } $m=ma/g-N;Panax Notoginseng             if(m%2==0) -printf"lose\n"); the             Else +printf"win\n"); A         } the     } +     return 0; -}

E-Nana in Wonderland Series--inexplicable episode

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.