// http://www.spoj.com/problems/STPAR/
#include <iostream>
#include <stack>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int num = 0;
cin >> num;
const int NOTSET = -1;
stack<int> waitting;
int car = 0;
int lastcar = 0;
bool carmoved = false;
while (num != 0) {
for (int i = 0; i < num; i++) {
cin >> car;
carmoved = false;
while (true) {
// first, try to move car from side street
if (waitting.size()!=0 && (waitting.top() == (lastcar+1))) {
lastcar = waitting.top();
waitting.pop();
continue;
}
// try move current car forward
if ((lastcar+1) == car) {
lastcar = car;
carmoved = true;
continue;
}
if (waitting.size()!=0 && (waitting.top() == (lastcar+1))) {
continue;
} else {
if (!carmoved) waitting.push(car);
break;
}
}
}
if (lastcar == num) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
waitting.empty();
lastcar = 0;
car = 0;
cin >> num;
}
}
SPOJ STPAR
最新推荐文章于 2025-06-15 10:05:58 发布