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

一星期后回归poj第一题留念~

Posted by ybc_c at 2010-12-08 00:41:04 on Problem 1363
#include "stdio.h"
#include "math.h"
#include "string.h"
#define M 1300

int train[M],visit[M];
int station[M];
int n;

int main()
{
	bool flag=true;
	while(1)
	{
		if(flag==true) {scanf("%d",&n);flag=false;}
		if(!n) break;
		for(int i=0;i<n;i++)
		{
			scanf("%d",&train[i]);
			if(!train[i]) {flag=true;break;}
		}
		if(flag==true) {printf("\n");continue;}
		else
		{
			int top=0,k=0;
			for(int i=1;i<=n;i++)
			{
				while(top && station[top-1]==train[k])    {k++;top--;}
				station[top++]=i;			}
			if(!top) printf("Yes\n");
			else
			{
				while(top)
				{
					if(station[top-1]==train[k]) k++;
					top--;
				}
				if(k==n) printf("Yes\n");
				else printf("No\n");
			}
		}
	}
	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