Bzoj 1411 [ZJOI2009] coin game

Source: Internet
Author: User

"Topic link"

http://www.lydsy.com/JudgeOnline/problem.php?id=1411

Test instructions

n coins are placed on a round table with a 2*n position, seeking the situation after the T operation. For an operation, if both sides are positive or both are negative, put a negative in the middle, otherwise put a positive.

Ideas

Set the positive to 0 and the negative to 1, then the state of a coin is either the coin or the other.

Think of two operations as one time, and the position will not change until the status of the coin is changed after one operation.

It is obtained by mathematical induction: The state of a coin is the 2^k of its left and right side of the coin after Operation 2^k. The intuitive view is that the middle items are or are eliminated.

The T/2 is split in binary and is continuously operational. Finally, we consider the parity of T.

Code

1#include <cmath>2#include <queue>3#include <vector>4#include <cstdio>5#include <cstring>6#include <iostream>7#include <algorithm>8 #definefor (A,B,C) for (int a= (b); a<= (c); a++)9 using namespacestd;Ten  OnetypedefLong Longll; A Const intN = 5e5+Ten; -  - ll Read () { the     CharC=GetChar (); -ll f=1, x=0; -      while(!IsDigit (c)) { -         if(c=='-') f=-1; C=GetChar (); +     } -      while(IsDigit (c)) +x=x*Ten+c-'0', c=GetChar (); A     returnx*F; at } -  - intN; ll m; - intA[n],ans[n]; -  - intMain () in { -     //freopen ("in.in", "R", stdin); to     //freopen ("Out.out", "w", stdout); +N=read (), m=read (); -for (I,1, n) ans[i]=read (), ans[i]--; thell x=m/2; *      for(LL p=1;p <=x;p<<=1)if(x&p) { $memcpy (A,ans,sizeof(int) * (n+1));Panax Notoginsengll k=p%N; -          for(intI=1; i<=n;i++) { thell l= (i-1-k+n)%n+1, R= (i-1+K)%n+1; +ans[i]=a[l]^A[r]; A         } the     } +ans[0]=ans[n],ans[n+1]=ans[1]; -     if(m&1) for (I,1, N-1) printf ("0%d", (ans[i]^ans[i+1])+1); $     Elsefor (I,1, N-1) printf ("%d 0", ans[i]+1); $     if(m&1) printf ("0%d", (ans[n]^ans[n+1])+1); -     Elseprintf"%d 0", ans[n]+1); -     return 0; the}

Can you be more headstrong, =-=?

Bzoj 1411 [ZJOI2009] coin 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.