Rails UVA - 514
阿新 • • 發佈:2018-12-08
#include <iostream> #include <stack> #include <cstdio> using namespace std; const int N = 1000; int target[N]; stack<int> s; int n; int Judge() { int head = 0, num = 1; while(head < n) { if(num == target[head]) num++, head++; else if(!s.empty() && s.top() == target[head]) { s.pop(); head++; } else if(num <= n) s.push(num++); else return 0; } return 1; } int main() { while(~scanf("%d", &n) && n) { while(1){ while (!s.empty()) s.pop(); scanf("%d", &target[0]); if (target[0] == 0) break; for (int i = 1; i < n; i++) scanf("%d", &target[i]); printf("%s\n", Judge()? "Yes" : "No"); } printf("\n"); } return 0; }