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

高手们帮我看下什么数据会runtime error

Posted by gzw_02 at 2008-07-07 17:38:53 on Problem 3437
# include <stdio.h>
# include <string.h>

char seq[10001];
int dp[10001];
int get_depth(int s,int e,int bd,int h){
	int p,i,k=1,ns,ne,maxh=h;
	if(s==e) return bd;
	for(i=s;i<=e;i++){
		if(dp[i]==h) {
			ns=i;
			while(dp[++i]!=dp[ns]&&i<=e);
			ne=i;
			if((p=get_depth(ns+1,ne-1,bd+k,h+1))>maxh)
				maxh=p;
			if(ne==e) break;
			k++;
            i=ne-1;
		}
	}
	return maxh;
}
int main(){
	int i,len,th,bh,cur,tn=0;
    dp[0]=0;
	while(scanf("%s",&seq),strcmp(seq,"#")){
		tn++;
		cur=bh=th=0;
		len=strlen(seq);
		for(i=0;i<len;i++){
			if(seq[i]=='d'){
				cur++;
				if(cur>th) th=cur;
			}else cur--;
			dp[i+1]=cur;
		}
		bh=get_depth(0,len,0,0);
		printf("Tree %d: %d => %d\n",tn,th,bh);
	}
	  	return 1;
}


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