Background: 1A
Idea: Stack Simulation
My Code:
#include <set> #include <stack> #include <queue> #include <vector> #include <cstdio># Include <map> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm > #define LL Long Long intusing namespace Std;const int m=1009,inf=0x3fffffff;int n,train[m];int main (void) {Log:while ( scanf ("%d", &n), N) {while (true) {stack<int> s1,s2; BOOL Ans=false; for (int i=1;i <= n;i++) {scanf ("%d", &train[i]); if (!train[i]) {printf ("\ n"); Goto log; } s1.push (n-i+1); } for (int i=1;; i++) {if (i > N) {ans=true;break;} if (!s2.empty () && s2.top () = = Train[i]) {s2.pop (); }else if (!s1.empty () && train[i] >= s1.top ()) {while (true) {if (!s1.em Pty () && S1.top () = = Train[i]) {s1.pop (); Break } int temp=s1.top (); S1.pop (); S2.push (temp); }}else break; } if (ans) printf ("yes\n"); else printf ("no\n"); }} return 0;}
UVa 514 Data Structure stack