Nyoj stone acquisition (3) (applying the theorem of nyoj game)

Source: Internet
Author: User

Stone (3)

Time Limit: 1000 MS | memory limit: 1000 kb

Difficulty: 6

Description

Mr. Wang liked to play some small games with his colleagues. Today they chose to play with stones.

The game rules are as follows: there are n stones in total, and the number of stones in each heap is known. Two people take turns to take the child, and each time they can only select one of N heap stones, take a certain number of stones (at least one, you can also randomly select a few of the remaining stones in the heap and place them in any other pile or pile. When someone cannot get the game, it means that this person has lost the game. Note: After a pile of stones have no child, you cannot place stones here.

Assume that every time Mr. Smith takes stones and both sides of the game are absolutely smart. Now, let's determine whether Mr. Smith can win the game by giving you the number of stones and the number of stones each heap.

For example, if four stones exist at the beginning, the number of stones is 3 1 4 2, but Mr. Wang wants to decide to take two stones from the third pile of stones first (the State of the stone heap changes to 3 1 2 2), and then he can make the stone heap reach the following states:

3 1 2 2 (no longer moving stones)

4 1 1 2 (move to the first heap)

3 2 1 2 (move to the second heap)

3 1 1 3 (move to the fourth heap)

5 1 0 2 (move all to the first heap)

3 3 0 2 (move all to the second heap)

3 1 0 4 (move all to the end)

Input

Multiple groups of test data may exist (the number of test data groups cannot exceed 1000)
The first line of each group of test data is an integer, indicating N (1 <= n <= 10)
The second row contains N integers, indicating the number of stones in the heap. (The number of stones per heap cannot exceed 100)
When the input N is 0, it indicates that the input is complete.

Output

For each group of test data, the output win indicates that John can win, and the output lose indicates that John will lose.

Sample Input

3

2 1 3

2

1 1

0

Sample output

Win

Lose

Ideas:

It uses a theorem of the nheim game:

As long as there are odd numbers of the same heap number, it is a winning state.

The Code is as follows:

<Span style = "font-size: 14px;" >#include <stdio. h> # include <string. h> int A [110]; // array a is used to count the number of times each heap appears. Int OK (int * A) // determines whether the heap is a singular situation. If there is an odd number of heap instances, the number of non-singular heap instances can be determined ). {For (INT I = 0; I <110; I ++) if (a [I] & 1) return 1; return 0 ;}int main () {int N, i, m; while (~ Scanf ("% d", & N), n) {memset (A, 0, sizeof (a); for (I = 0; I <n; I ++) {scanf ("% d", & M); A [m] ++;} printf ("% s \ n", OK ()? "Win": "lose");} return 0; </span>


Nyoj stone acquisition (3) (applying the theorem of nyoj game)

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.