[Bzoj 1115] [POI2009] Stone game kam "Ladder Game"

Source: Internet
Author: User

Title Link: BZOJ-1115

Problem analysis

First look at the ladder game:

Ladder game refers to: the initial n heap of stones, each time can be from any heap to take a number of gravel into the i-1 heap. The person who ultimately cannot operate fails.

Solution: The odd bit of gravel heap to do the most basic NIM on it.

Why: The winner of the odd digit NIM is always able to win, because if you take a stone from an odd digit to an even digit, it is equivalent to take these stones away, that is, Nim; if the loser takes the stone from an even digit to an odd number, the winner can always move the Stones forward one position, and then put them in even digits. If you keep moving, you will end up with a winner who will take the stones to the 0 position, and the loser will no longer be able to move the stones. Just as there is no change, an even number of stones will have no effect on our game.

Then take a look at the problem and ask for assurances that the monotony will always be met.

We make a difference to the stone, i.e. b[i] = A[i]-a[i-1]. Then you will find that a stone from the first heap is equivalent to the b[i]-= 1, b[i + 1] + = 1, then is a backward step NIM, from the forward to take the odd bit of Bi xor.

Code
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include < Algorithm> #include <cmath>using namespace Std;const int maxn = + 5;int T, N;int A[MAXN], B[maxn];int main () { scanf ("%d", &t); for (int case = 1; Case <= T; ++case) {scanf ("%d", &n), for (int i = 1; I <= n; ++i) scanf ("%d", &a[i]), for (int i = 1; I <= n; ++i) B[i] = A[i]-A[i-1];int temp = 0;for (int i = n; i > 0; I-= 2) Temp ^= b[i];if (temp) printf ("tak\n"); else printf ("nie\n") ;} return 0;}

  

[Bzoj 1115] [POI2009] Stone game kam "Ladder Game"

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.