Stone game, stone game

Source: Internet
Author: User

Stone game, stone game

Http://blog.csdn.net/pipisorry/article/details/39120867

Problem description:

A and B face several stones, and the number of each pile of stones can be determined at will. The two take turns to take some stones according to the following rules. The rules of the game are as follows: 1. each step should take at least one stone; 2. each step can only take part or all of the stones from a pile; 3. if no one can obtain the child according to the rule, the loser is the loser. If both Party A and Party B adopt the best strategy, Party A should take the lead. Will it be a win or B win. input Format: multiple groups of data. Each group has two rows. The first row is an integer N, 2 <=n <= 10000. The next row is a positive integer N, indicates the number of stones in each heap. The number of stones is within 32 integers. Output Format: one row is output for each group of test data. If a has a winning strategy, "Win" is output; otherwise, "Lost" is output"

Problem from [http://hero.csdn.net/]
Challenge rules:

Input example

3 3 3 1

Output example:

Win


Solution code:




From:

Http://blog.csdn.net/pipisorry/article/details/39120867

Ref:



Stone game

This is an optimal strategy problem in number theory, without the mean principle.
I want to give you a better answer.
Coming to work, continue thinking after work ...... (Reply only when there is not much time. Sorry)
1. It is correct to remove 32 of the remaining 18 from 50.
2. algorithm: Obtain n from one heap, so that all the remaining numbers are exactly "mandatory" (in this case, the mandatory loss is obtained first )".
3. the so-called "mandatory negative" refers to converting the number of each remaining heap into a binary number, then adding them, and specifying an addition without carrying (that is, an exclusive or operation ), that is, 0 + 0 = 0, 1 + 0 = 0, 0 + 1 = + 1 = 0 (do not carry). If the sum is 0 (multiple zeros ), this situation is called a "mandatory situation ".
4. "mandatory" Principle: A "mandatory", a change to any number will no longer be "mandatory", at the same time, any "non-mandatory ", by correctly reducing a certain number, the Operation will surely become "mandatory", and this operation is unique. Imagine that it is "mandatory". If you take it first, you must change 1 of a certain number to 0 and 0 to 1. It must not be "mandatory" anymore, but I can definitely make it "mandatory ". In fact, this situation is equivalent to an even number. If you get it, it must correspond to what I get, so I must get the last one. To put it simply, there are only two stacks. If they are not equal, they are "not mandatory". The winner must win the game first, as long as you get more than one heap to make the two heap equal, and then you get a few, I will get a few from the other heap.
5. Application: (The format may change)
19 010011
7 000111
5 000101
3 000011
010010 (18) 10
That is, it takes 18 seconds to become "mandatory", so 50-18 = 32
Therefore, for 1st times, only 32 particles can be taken from 5th piles of stones, so that after 32 particles are taken out, it is "mandatory", that is, the result of the exclusive or operation is 0.

Stone game

It is difficult for both parties to adopt the best strategy.
But I will think about it. Maybe it will be done in a few days.
 

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.