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*