Test instructions is still well understood, according to the topic to give a description of the conditions and then find out the string of queue
My approach is to use two arrays before[] and after[] to represent the previous person's number in front of AI and the number of people behind the AI.
Ex[] represents the number of times AI is entered, and this array is used when the number of people is odd, looking for a 1th person to study the number, as long as the 1-10^6 can be traversed once
Specific or look at the code bar Qaq, feel the code is better understood.
"This topic RE at least 5 times, the real reason is that the array does not open in place = =, also really feel that they have not written code a good weak ...
1 //#pragma COMMENT (linker, "/stack:16777216")//For C + + Compiler2#include <stdio.h>3#include <iostream>4#include <cstring>5#include <cmath>6#include <stack>7#include <queue>8#include <vector>9#include <algorithm>Ten #definell Long Long One #defineMax (b) ((a) > (b))? (a): (b)) A #defineMin (b) ((a) < (a))? (a): (b)) - #defineAbs (x) (((x) > 0)? (x): (-(x))) - the using namespacestd; - - Const intINF =0x3f3f3f3f; - inta[200011], ex[1000011]; + intbefore[1000011], after[1000011]; - + intMain () { A intI, J, K, T, N, M; at intUU, VV, cur, pos; - while(EOF! = scanf ("%d",&N)) { -Memset (ex,0,sizeof(ex)); -Memset (Before,-1,sizeof(before)); -Memset (After,-1,sizeof(after)); - for(i =1; I <= N; ++i) { inscanf"%d%d",&uu,&vv); -AFTER[UU] =VV; toBEFORE[VV] =UU; + if(UU = =0){ -a[2] =VV; the}Else if(VV = =0){ *A[n-1] =UU; $}Else{Panax Notoginseng++Ex[uu]; -++EX[VV]; the } + } A if(n%2==0){ theCur = a[2]; +pos =2; - while(POS! =N) { $pos + =2; $Cur = a[pos] =After[cur]; - } -cur = a[n-1]; thePOS = n-1; - while(POS! =1){Wuyipos-=2; theCur = a[pos] =Before[cur]; - } Wu}Else{ -Cur = a[2]; Aboutpos =2; $ while(pos! = N-1){ -pos + =2; -Cur = a[pos] =After[cur]; - } A for(i =1; I <=1000001; ++i) {//2 Nums + if(Ex[i] = =1&& Before[i] = =-1){ the Break; - } $ } thea[1] =i; theCur = a[1]; thepos =1; the while(POS! =N) { -pos + =2; inCur = a[pos] =After[cur]; the } the } About the for(i =1; I <= N; ++i) { theprintf"%d", A[i]); the } +printf"\ n"); - } the return 0;Bayi } the /* the 8 - 3 0 - 5 4 the 1 5 the 0 7 the 9 the 9 6 - 6 3 the 7 1 the 5 the 3 094 5 3 the 0 5 the 6 4 the 4 298 */
Codeforces 490B Queue "Analog"