BZOJ1106[POI2007] Cube Big battle tet*

Source: Internet
Author: User

BZOJ1106[POI2007] cube big battle tet

Test instructions

Given the player a stack with 2n elements, these elements have n different numbers, with exactly two elements per number. The player can exchange two adjacent elements at a time. If, after the swap, the two adjacent elements are numbered identically, they are removed from the stack and all elements above them fall and can cause a chain reaction. The minimum number of steps will eliminate all blocks.

Exercises

With a stack maintenance, if you encounter a number not encountered in the stack, otherwise let the previous element out of the stack, two elements between the elements move down one bit, and the distance of two elements into the answer.

Code:

1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineInc (I,J,K) for (int i=j;i<=k;i++)5 #defineMAXN 1000106 using namespacestd;7 8InlineintRead () {9     CharCh=getchar ();intf=1, x=0;Ten      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} One      while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); A     returnf*x; - } - intSt[maxn],top,ans,n;BOOL inch[MAXN]; the intMain () { -n=read (); -Inc (I,1,2*N) { -         intx=read (); +         if(!inch[x])inch[x]=1, St[++top]=x;Else{ -             intJ=top; while(st[j]!=x) j--; Inc (k,j,top-1) st[k]=st[k+1],ans++; top--;inch[x]=0; +         } A     } atprintf"%d", ans);return 0; -}

20160810

BZOJ1106[POI2007] Cube Big battle tet*

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.