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

阿牛!帮我看看啊! 那个地方有问题啊!

Posted by ecjtuQX at 2008-07-28 18:59:54 on Problem 2251
#include<stdio.h>
struct space
{
	int x;
	int y;
	int z;
	int time;
};
struct space q[27010];
int R,C,L,sx,sy,sz,ex,ey,ez;
char map[31][31][31];
int use[31][31][31];
int dir[6][3]={{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};//表示6个搜索的方法
In(int x,int y,int z)
{
	if(x>=0&&x<L&&y>=0&&y<R&&z>=0&&z<C)
		return 1;
	else
		return 0;
}

int BFS()
{
	int i,x,y,z,top=1,base=0;
	struct space a;
	while(top!=base)
	{
		if(q[base].x==ex&&q[base].y==ey&&q[base].z==ez)
		   return q[base].time;
		a=q[base++];
		for(i=0;i<6;i++)
		{
			x=a.x+dir[i][0];
			y=a.y+dir[i][1];
			z=a.z+dir[i][2];
			if(In(x,y,z)&&!use[x][y][z])
			{
				q[top].x=x;
				q[top].y=y;
				q[top].z=z;
				q[top].time=a.time+1;
				use[x][y][z]=1;
				if(x==ex&&y==ey&&z==ez)
					return q[top].time;
				top++;
			}
		}
	}
	return -1;

}
int main()
{
	int i,j,k,min;
	char s[80];
	while(scanf("%d%d%d%*c",&L,&R,&C)&&(R||C||L))
	{    
		  memset(use,0,sizeof(use));
          for(i=0;i<=L-1;i++)
		  {
			  for(j=0;j<=R-1;j++)
			  {
				  gets(map[i][j]);
				  for(k=0;k<=C-1;k++)
				  {
					  if(map[i][j][k]=='S')
					  {
						  sx=i;
						  sy=j;
						  sz=k;
					  }
					  if(map[i][j][k]=='E')
					  {
						  ex=i;
						  ey=j;
						  ez=k;
					  }
				  }
				 	  
			  }
			   gets(s);
		  }
			printf("%d %d %d \n",ex,ey,ez);

        /*
		for(i=0;i<=L-1;i++)
		{
			for(j=0;j<=R-1;j++)
			{
				for(k=0;k<=C-1;k++)
					printf("%c",map[i][j][k]);
				printf("\n");
			}
			printf("\n\n");
		}
		*/
			  q[0].x=sx;
			  q[0].y=sy;
			  q[0].z=sz;
			  q[0].time=0;
			  use[sx][sy][sz]=1;
		   min=BFS();
		   printf("%d\n",min);
		   if(min==-1)
			   printf("Trapped!\n");
		   else
			   printf("Escaped in %d minute(s).\n",min);
	}
	return 0;
}

/*
3 4 5
S....
.###.
.##..
###.#

#####
#####
##.##
##...

#####
#####
#.###
####E

1 3 3
S##
#E#
###


0 0 0

Escaped in 11 minute(s).
Trapped!

*/

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