ZOJ 1259 Rails
2014-07-23 01:13
381 查看
stack的应用
#include<iostream> #include<cstdio> #include<stack> using namespace std; int goal[1005]; int d[1005]; stack<int>s; int main() { freopen("input.txt","r",stdin); int n; for(int i = 0; i <= 1000; i++) d[i] = i; while(cin>>n && n) { while(cin>>goal[1] && goal[1]) { while(!s.empty()) s.pop(); for(int i = 2; i <= n; i++) cin>>goal[i]; int i = 2; int pos = 1; s.push(d[1]); while(pos <= n && i <= n+1) { if(s.empty() || s.top() != goal[pos]) { s.push(d[i]); i++; } else if(s.top() == goal[pos]) { s.pop(); pos++; } else break; } if(s.empty()) cout<<"Yes"<<endl; else cout<<"No"<<endl; } cout<<endl; } return 0; }
相关文章推荐
- zoj 1259 Rails.
- ZOJ 1259 Rails
- zoj 1259 Rails
- zoj 1259 || poj 1363 Rails(栈~!)
- zoj 1259 || poj 1363 rails(栈)
- zoj1259-Rails
- ZOJ 1259_Rails
- zoj - 1259 - Rails
- ZOJ Problem Set -1259 Rails
- zoj - 1259 - Rails
- ZOJ Problem Set -1259 Rails
- ZOJ-1259-Rails
- ZOJ-1259-Rails
- ZOJ 1259(Rails)
- zoj 1259 Rails
- zoj 1259
- ZOJ-1259 输出所有的出站情况
- ZOJ-1259
- ZOJ 1259
- zoj(Strange Calendar III)