[XSY2271] frog (stack)

include<bits/stdc++.h>

define N 200010

using namespace std;

int n,a[N],p[N],st[N],top;

void NO()
{
puts("No");
exit(0);
}

int main ()
{
Scanf ( "% D", & n-);
for (int I =. 1; I <n-; I ++)
Scanf ( "% D", & A [I]);
for (int I =. 1; I < n-=; I ++)
{
IF (A [I] == A [-I. 1]) // jump their own
P [I] = I;
the else IF (A [I] == A [-I. 1] +2 ) // i right jump
ST [Top ++] = I;
the else IF (A [I] == A [-I. 1] -2) // i jump to the left
{
IF (Top) // i go! left jump, if nobody left to skip, jump over it shows i
nO ();
P [ST [Top]] = i;
P [i] = ST [top--];
}
the else
nO (); // because each a [i] is obtained two adjacent even and differ by no more than 2, the other are not met
}
IF (Top) as well as the stack // frog jump to right, indicating illegal
nO ();
the puts ( "Yes");
for (int I =. 1; I <= n-; I ++)
the printf ( "% D", P [I]);
return 0;
}

Guess you like

Origin www.cnblogs.com/ez-lcw/p/11491303.html