[Step game] BZOJ1115: [POI2009] Pebble game kam__--------------Math related------------

Source: Internet
Author: User

Learned the ladder game that I have not seen before:
Ladder game is n steps, there are a number of stones on the steps, each time you can choose any pile down a layer to move any (stone to 1 layers below can not move), can not operate the people lose.
This can be converted to a Nim game, that is, the odd number of step stones of the different or and. Proving similar, a 0 state can only go to a non-0 state, and not a 0 state must have a method transfer to the 0 state.

You can do this by knowing this. Considering the difference of adjacent stones, when taking a heap of rock, the decrease of the difference between I and i-1 equals the increase of the difference between i+1 and I, and the difference is always guaranteed to be nonnegative.
This is converted into a ladder game model.

#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=2005;
int _TEST,N,A[MAXN];
int main () {
    freopen ("bzoj1115.in", "R", stdin);
    Freopen ("Bzoj1115.out", "w", stdout);
    scanf ("%d", &_test);
    while (_test--) {
        scanf ("%d", &n);
        for (int i=1;i<=n;i++) scanf ("%d", &a[i]);
        int ans=0;
        for (int i=n;i>=1;i-=2) ans^= (a[i]-a[i-1]);
        if (ans) printf ("tak\n"); else printf ("nie\n"); 
    }

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.