Poj 1704 Georgia ans Bob (staircase-nim)

Source: Internet
Author: User

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

Put the array upside down (17 14 12 9 7 6 5 1), regard the spacing of adjacent pieces as a pile of stones (2 1 2 0 0 3 ), the operation in the question is to put n of the last pile of stones into the previous pile of stones, which is converted into a tiered game. It's okay to use the tiered game solution for odd bit or odd bit.

In other blogs, we also see a solution that groups two groups from the backend and adds a zero node to the front of an odd vertex. Consider the distance between two nodes as a pile of stones.

1. If the opponent moves the first of the two, the last one will certainly be able to move the same number of locations.

2. If the opponent moves the last one of the two, it is equivalent to taking N from the pile of stones.

Isn't that a tiered game? The operation on the even heap can be ignored. The odd heap is an exception or a solution. Why does it look amazing...

Code:

# Include <cstdio>
# Include <cstdlib>
Int data [1001];
Int CMP (const void * a, const void * B ){
Return * (int *) A <* (int *) B? -1: 1;
}
Int main (){
Int t, n, I, j, sum;
Scanf ("% d", & T );
While (t --){
Sum = 0;
Scanf ("% d", & N );
Data [0] = 0;
For (I = 1; I <= N; I ++)
Scanf ("% d", & Data [I]);
Qsort (data, n + 1, sizeof (data [0]), CMP );
For (I = N; I> 0; I-= 2)
Sum ^ = (data [I]-data [I-1]-1 );
If (SUM) printf ("Georgia will win \ n ");
Else printf ("Bob will win \ n ");
}
Return 0 ;}

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.