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 yinshaohua67 at 2009-06-23 19:39:03 on Problem 1573 and last updated at 2009-06-23 19:47:51
#include<stdio.h>
#include<memory.h>
int loop, out, row,col;
char map[12][12];
int step[12][12];
bool isok(int i,int j)
{
	if(i>=0&&i<row&&j>=0&&j<col&&!step[i][j])
		return true;
	else
		if(step[i][j])
		{
			loop=out-step[i][j]+1;
			out-=loop;
		}
	return false;
}
void func(int i,int j)
{
switch (map[i][j])
{
case 'N':
	   if (isok(i-1,j))
	   {
		   out++;
		   step[i-1][j]=step[i][j]+1;
		   func(i-1,j);
	   }
	   break;
case 'W':
	   if (isok(i,j-1))
	   {
		   out++;
		   step[i][j-1]=step[i][j]+1;
		   func(i,j-1);
	   }
	   break;
case 'E':
	   if (isok(i,j+1))
	   {
		   out++;
		   step[i][j+1]=step[i][j]+1;
		   func(i,j+1);
	   }
	   break;
case 'S':
	   if (isok(i+1,j))
	   {
		   out++;
		   step[i+1][j]=step[i][j]+1;
		   func(i+1,j);
	   }
	   break;
}
}
int main()
{
	int stand;
	int i,j;
	scanf("%d%d%d",&row,&col,&stand);
	while(row!=0&&col!=0)
	{
		loop=0;
		out=1;
     memset(step,0,sizeof(int));
     for(i=0;i<row;++i)
		 scanf("%s",map[i]);
	  step[0][stand-1]=1;
      func(0,stand-1);
	  if(loop)
		  printf("%d step(s) before a loop of %d step(s)\n",out,loop);
	  else
		  printf("%d step(s) to exit\n",out);
      scanf("%d%d%d",&row,&col,&stand);
	}
	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