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

why Runtime error

Posted by team29 at 2005-10-19 17:57:20 on Problem 1979
#include <iostream.h>
char ch[20][20];
int flag[20][20]={0};
static int x,y,q=0;
static int p1[100]={0},p2[100]={0};
int count=0;
int rsearch(int l,int k);
void del()
{
	int i,t;
        for(i=0;i<20;i++)
		 for(t=0;t<20;t++)
			flag[i][t]=0;
		for(i=0;i<20;i++)
		 for(t=0;t<20;t++)
			ch[i][t]='0';
}
int  main()
{
	
	int w,h,i,t;
	
	while(1)
	{
	cin>>w>>h;
	if(w==0&&h==0) break;
		for(i=0;i<h;i++)
	  for(t=0;t<w;t++)
	   {
		   cin>>ch[i][t];
		   
		   if(ch[i][t]=='@') 
		   {
			   x=i;y=t;
			   
			   p1[0]=x,p2[0]=y;
		   }
		   else 
			   continue;
	   }
	   
	
	rsearch(x,y);
	cout<<count+1<<endl;
	      del();  
		x=0;y=0;q=0;count=0;
       
	}
   return 1;
}
int rsearch(int l,int k)
{
	 		
	 if(ch[l+1][k]=='.'&&flag[l+1][k]==0) 
	{
		q++;count++;
		p1[q]=l+1;p2[q]=k;
		
		flag[l+1][k]=1;
		rsearch(l+1,k);
	}
	else if(ch[l-1][k]=='.'&&flag[l-1][k]==0)
	{
		q++;count++;
		p1[q]=l-1;p2[q]=k;
		
		flag[l-1][k]=1;
		rsearch(l-1,k);
	}
	else if(ch[l][k+1]=='.'&&flag[l][k+1]==0)
	{
		q++;count++;
		p1[q]=l;p2[q]=k+1;
		
		flag[l][k+1]=1;
		rsearch(l,k+1);
	}
	else if(ch[l][k-1]=='.'&&flag[l][k-1]==0)
	{
		q++;count++;
		p1[q]=l;p2[q]=k-1;
		
		flag[l][k-1]=1;
		rsearch(l,k-1);
	}
	else if(ch[l][k]=='@'&&q==0)
	{
		return 1;
	}
	else 
	{
		q--;
		rsearch(p1[q],p2[q]);
	}
	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