标签:
栈
#include<cstdio> #include<cmath> #include<cctype> #include<iostream> #include<vector> #include<cstring> #include<algorithm> #include<map> #include<set> #include<cstddef> #include<sstream> #include<cstdlib> #include<stack> #include<queue> using namespace std; const int MAXN = 1000 + 10; int n, target[MAXN]; int main() { while(cin >> n) { stack<int> s; int A = 1, B = 1; for(int i = 1; i <= n; i++) cin >> target[i];//初始化火车 int ok = 1; while(B <= n) { if(A == target[B]) { A++; B++; } else if(!s.empty() && s.top() == target[B]) { s.pop(); B++; } else if(A <= n) s.push(A++); else { ok = 0; break; } } cout << (ok ? "Yes" : "No") << endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/liangyongrui/p/4471884.html