PKU-1704-Georgia and Bob

Source: Internet
Author: User

Question Link

Http://poj.org/problem? Id = 1704

This question is a good question, but it cannot be done in two cases. I have obtained the question, asked you to sort it, and how to turn it into something we are familiar,

In this question, I started to sort by choice. He gave me a wang answer. I don't understand it, but I am not grateful if I use sort AC!

The idea of the question (from the internet) is a pity that the question cannot be understood, let alone the idea.

This question was made during ACM training during the summer vacation, and is used in the form of an NLE game. When I first started this question, consider the distance between any two pieces as a pile of stones (or cards) in the nheim game ). This idea is too naive. After expert guidance, I found that I had to pair the chess pieces. Now let's assume that this is the case-every two pieces are next to each other. This state is a defeat. No matter which chess piece you move, the next player will move another chess piece so that they will be next to it again. In this way, we can think of moving the front and back as the same state, so we can assume that the front of the pair is not moving, and the distance of the last piece is reduced, who can finally make the matching pieces all next to who will win (just like taking a pile of stones away from the Nimes game, who finally wins who wins ). Careful people will find that if the number of chess pieces is odd, how can they be paired? If the number of chess pieces is from the past to the next, the status of the last chess piece is not fixed, so they will accompany them from the back. The first pawn can be imagined as pairing with the left boundary. The input examples in poj are from small to large, but are not described in the question. Therefore, we need to sort the input data to get a correct solution.


There was no idea at all when I started to see this question, but the explanation for "looking for a failed State-a quick solution to a class of problems" is as follows:

Analysis:
At first glance, the movement of the chess piece is subject to the limitations of other chess pieces. It seems that it is impossible to find a general solution, but a careful analysis will find that there are holes in the sky.

The maximum number of steps a piece moves to the left at a time is fixed, and as the Movement decreases, isn't it like taking stones? So what is the difference between it and taking stones? It is because every movement will increase the space of the adjacent pawns on the right. This is different from the stone-taking function, which only reduces and does not increase. How should we solve this problem?
We do not give up matching it with the stone we are familiar with, but we make small changes to our strategy:

Divide each piece from the right end to the left end into a pair. If only one piece is left, add a grid to the left end of the board and match the piece, in this way, it seems that after pairing is no different from before, but it is much easier to make decisions, because we do not have to care about the distance between groups, when the opponent moves a set of chess pieces on the left, we only need to move the one on the right to the same number of steps! At the same time, we regard the distance between each two pieces as a pile of stones. When the opponent moves the right of the two pieces, we play the stone game with him, in this way, the question corresponds to the stone.
This example shows that many models seem complex, but after some clever changes, they can be converted into some familiar models, and fully reflect the flexibility of the game.
If the previous example describes the application of this idea, the following method is to explain the superiority of this idea, this is because this question is not the old road to "manually pushing small data => conjecture => proof", but directlyUse properties to derive mandatory conditions.

In fact, after reading the above analysis, I still don't quite understand it. I searched the internet for the following explanations, which is easier to understand:

/* Since any two adjacent pawns are only related to the vacant space between them, they can be converted into normal Nim games: we can regard these vacant spaces as the number of stones, whoever makes the last vacancy is the winner. */

 

My code

Here N = 1 should be considered separately.

 

# Include <stdio. h>
# Include <iostream>
# Include <algorithm>
Using namespace STD;

 

Int main (void)
{
Int t, n, a [10005], K, I, J;
Scanf ("% d", & T );
While (t --)
{
K = 0;
A [0] = 0;
Scanf ("% d", & N );
For (I = 1; I <= N; I ++)
Scanf ("% d", & A [I]);
Sort (a + 1, A + n + 1 );
/* For (I = 1; I <= N; I ++)
{
For (j = I + 1; j <= N; j ++)
{
If (A [I]> A [J])
A [I] = A [I] ^ A [J] ^ (A [J] = A [I]);
}
}*/
If (n = 1 & A [1] = 1)
Printf ("Bob will win \ n ");
Else if (n = 1 & A [1]! = 1)
Printf ("Georgia will win \ n ");
Else
{
If (N % 2)
{
For (I = 1; I <= N; I ++, I ++)
K = K ^ (A [I]-A [I-1]-1 );
}
Else
{
For (I = 2; I <= N; I ++, I ++)
K = K ^ (A [I]-A [I-1]-1 );
}
If (k = 0)
Printf ("Bob will win \ n ");
Else
Printf ("Georgia will win \ n ");
}
}
Return 0;
}

 

 

This is a good question.

PKU-1704-Georgia and Bob

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.