"bzoj1115" [POI2009] Stone game kam (game theory)

Source: Internet
Author: User
Tags gcd

Topic Portal: https://www.lydsy.com/JudgeOnline/problem.php?id=1115

Observing the problem, we can find that the number of adjacent two piles of gravel is not negative, and we are in the first heap of stones to remove the K-stone, then the number of the heap and the i-1 heap of gravel is reduced k, the number of i+1 heap and the amount of the heap is increased k. This translates to a classic game theory: Ladder Games. We remove the first heap of Stones K, then it is equivalent to the ladder on the first heap and the i-1 heap stones of the difference between the level of k stones to the I+1 heap and the first heap of the difference that level (move down one level). So there is a conclusion: ladder game results = take the odd ladder of stones to play Nim game.

Code:

#include <cstdio>#include<cmath>#include<cstdlib>#include<cstring>#include<ctime>#include<string>#include<iostream>#include<algorithm>#include<queue>#include<vector>#include<map>#definell Long Long#defineull unsigned long Long#defineMax (A, B) (A&GT;B?A:B)#defineMin (A, b) (A&LT;B?A:B)#defineLowbit (x) (x&-X)#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineEPS 1e-18#defineMAXN 2000010inline ll read () {ll tmp=0;CharC=getchar (), f=1; for(;c<'0'||'9'<c;c=getchar ())if(c=='-') f=-1; for(;'0'<=c&&c<='9'; C=getchar ()) tmp= (tmp<<3) + (tmp<<1) +c-'0';returntmp*F;} Inline ll Power (ll A,ll b) {ll ans=1; for(; b;b>>=1){if(b&1) Ans=ans*a%mod; A=a*a%mod;}returnans;} inline ll gcd (ll A,ll b) {returnB?GCD (b,a%b): A;} InlinevoidSwapint&a,int&AMP;B) {intTmp=a; A=b; b=tmp;}using namespacestd;inta[1010];intN;intMain () {intt=read ();  while(t--) {n=read (); LL TMP=0;  for(intI=1; i<=n;i++) a[i]=read ();  for(inti=n;i>=1; i-=2) TMP^=a[i]-a[i-1]; if(TMP) printf ("tak\n"); Elseprintf"nie\n"); }}
bzoj1115

"bzoj1115" [POI2009] Stone game kam (game theory)

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.