Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么总是Time Limit Exceed啊!!!!!!!!????????????

Posted by 0761 at 2005-09-20 17:09:42 on Problem 1363
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator