| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么总是Time Limit Exceed啊!!!!!!!!????????????#include<iostream>
#include<stack>
using namespace std;
void main()
{
stack<int> coach,station; //coach栈内为用户所给顺序,station为另一栈
int a[1000],n,nn,t=0;
cin>>n;
nn=n;
while(n!=0){
cin>>a[0];
while(a[0]!=0){
for(int i=1;i<n;i++)
cin>>a[i];
for(int j=0;j<n;j++) //把输入元素都压入coach栈
coach.push(a[j]);
while(n>0){
if((!coach.empty())&&coach.top()!=n){ //coach栈非空且栈顶不是所找元素
station.push(coach.top()); //则将其压入station栈,并从coach栈中删除
coach.pop();
}
if((!coach.empty())&&coach.top()==n){ //coach栈非空且栈顶为所找元素,将其删除
coach.pop(); //并将所找元素n-1
n--;
}
if(n==0) break;
if((!station.empty())&&station.top()==n){//station栈非空且栈顶为所找元素,将其
station.pop(); //删除并将所找元素n-1
n--;
}
if(n==0) break;
if(coach.empty()&&station.top()!=n){ //coach栈为空且station栈站顶不是所找元素
if(t==1) {cout<<endl; t=0;} //则为no
cout<<"No"<<endl; //t标记为1时则换行
n=-1; //n为-1使跳出while循环
}
}
if(n==0){
if(t==1) {cout<<endl;t=0;} //若n为0跳出的循环则为yes
cout<<"Yes"<<endl;
}
n=nn;
cin>>a[0];
if(a[0]==0) t=1;
}
cin>>n;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator