E-Nana in Wonderland Series--inexplicable episode

Source: Internet
Author: User
Tags greatest common divisor

    • A
    • B
    • C
    • D
    • E
    • F
    • G
E-Nana in Wonderland Series--inexplicable episodeTime Limit:2000/1000ms (java/others) Memory Limit: 128000/64000kb (java/others) Submit Statusproblem 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

Submit

Test instructions

Each time you take two numbers from the set, and then calculate the difference of two to the two number of a-B (a), put the difference in the set until the collection cannot be placed, judging who wins who is negative. The collection does not appear the same element

Exercises

Each fetch two number of difference, put into the set, assuming that the collection as long as two number, each take two number of difference into the set, in which to take two number of the difference into the collection, you can know that the number in the set, will be the first two number of greatest common divisor, the set can put how many number, depending on the initial maximum number of sets The number of full elements s= the largest number of max/set greatest common divisor gcd, the number of the judgment can also be put, then times=s-the first number of elements of the collection. (The collection does not appear the same element, ensuring that the number of full collections can be determined ={d,2*d,... MAX},D=GCD (set);). All for the n number of sets, the set can put the number of numbers also equal to = the largest number max/set of greatest common divisor gcd, but also the number of times the times=s-collection of the initial number of elements, the number of times to judge the parity of the operation can know who wins who negative.

1 intGCD (intXintY/*the traditional gcd of non-recursion*/2 {3     intTmp;4      while(y)5     {6tmp=y;7y=x%y;8x=Tmp;9     }Ten     returnx; One } A intMain () - { -    intT,n,g_num,max; the    intnum[10086]; -scanf"%d",&T); -     while(t--) -    { +scanf"%d",&N); -scanf"%d", &num[0]); +g_num=num[0]; Amax=num[0]; at          for(intI=1; i<n;i++) -         { -scanf"%d",&num[i]); -G_NUM=GCD (G_num,num[i]);/*greatest common divisor for all maximum numbers*/ -             if(Max<num[i]) Max=num[i];/*find the maximum number in the collection*/ -         } in         if((max/g_num-n)%2) printf ("win\n");/*determine the parity of the number of operations*/ -         Elseprintf"lose\n");  to    } +     return 0; -}
View Code

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.