Poj 1704 Georgia and Bob (Tiered game)

Source: Internet
Author: User

This problem can be seen as a special stone game. Take the second example as an example:
1 5 6 7 9 12 14 17
The first pawn cannot be moved to the left. The second pawn can move three grids to the left. The third piece cannot be moved, and so on, you can get a series like this:
0 3 0 0 1 2 1 2 2, the nth number represents the number of steps that the nth piece can move.
Consider moving the second piece to the left, and the original sequence is:
0 2 1 0 1 2 2 2
Isn't that the second pile of stones moved to the third pile of stones on the right? Thus, we can give a new definition of equivalent games:
Given N piles of stones, the number of stones in each pile is non-negative. You can move any stone in heap I to heap I + 1 (1 <= I <N) or discard any stone in heap N. If someone cannot continue the operation, a negative result is returned.

Tiered game: http://blog.csdn.net/hlmfjkqaz/article/details/9612003

#include<iostream>#include<cstdio>#include<algorithm>using namespace std;#define N 1005int main(){    int t,i,j,a[N],n,s,b[N];    scanf("%d",&t);    while(t--)    {        scanf("%d",&n);        for(i=0;i<n;i++)           scanf("%d",&a[i]);        sort(a,a+n);        j=0;        for(i=n-1;i>0;i--,j++)        {           b[j]=a[i]-a[i-1]-1;        }        s=0;        b[n-1]=a[0]-1;        for(i=0;i<n;i+=2) s^=b[i];        if(s) puts("Georgia will win");        else puts("Bob will win");    }    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.