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

感觉没问题,但总是WA

Posted by magnetlei at 2011-02-04 22:08:54 on Problem 1363
#include<iostream>
#include<stack>
using namespace std;
int main()
{
	stack<int> s;
	int n,in,out[1001],i,j,k,flag,max;
	while((cin>>n)&&n!=0)
	{
		while(1)
		{
			cin>>out[1];
			if (out[1]==0) 
			{
				cout<<endl;
				break;
			}
			for (i=2;i<=n;i++) cin>>out[i];
			in=1;
			max=1;
			s.push(0);
			while(1)
			{
				if (out[in]>s.top())
				{
					for (i=max;i<out[in];i++) s.push(i);
					if (max<out[in]) max=out[in]+1;
					in++;
				}
				else if (out[in]==s.top()) 
				{
					s.pop();
					in++;
				}
				else if (out[in]<s.top())
				{
					cout<<"No"<<endl;
					break;
				}
				if (in>n) 
				{
					cout<<"Yes"<<endl;
					break;
				}
			}
		}
		while(!s.empty()) s.pop();
	}
	return 0;
}

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