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

Re:大牛帮忙看看找了一天w了n会就是不晓得哪里错了

Posted by k880331 at 2009-07-30 14:23:37 on Problem 2251
In Reply To:大牛帮忙看看找了一天w了你】 Posted by:k880331 at 2009-07-30 14:22:51
#include<stdio.h>
int maze[40][40][40];
int fx[6]={-1,1,0,0,0,0},fy[6]={0,0,-1,1,0,0},fz[6]={0,0,0,0,1,-1};
int qh,qe,L, R, C,bl;
char abc[40][40][40];
struct
{
	int x,y,z,pre;
}sq[2000000];
int BFS();
int checkout(int a,int b,int c);
int output();
int main()
{
	int a,b,c;
	while(scanf("%d%d%d",&L, &R, &C)&&L!=0&&R!=0&&C!=0)
	{
		bl=0;
		
		for (a=0;a<L;a++)
			for(b=0;b<R;b++)
				scanf("%s",abc[a][b]);
			for(a=0;a<40;a++)
				for(b=0;b<40;b++)
					for(c=0;c<40;c++)
						maze[a][b][c]=0;
					BFS();
						
			if(bl==0)
				printf("Trapped!\n");

	}
	return 0;
	


}
int BFS()
{
	int a,b,c,k;
	qh=-1;
	qe=0;
	sq[0].pre=-1;
	for(a=0;a<L;a++)
		for(b=0;b<R;b++)
			for(c=0;c<C;c++)
				if(abc[a][b][c]=='s')
				{
					sq[0].x=a;
					sq[0].y=b;
					sq[0].z=c;
				}
				while(qh!=qe)
				{
					qh++;
					for(k=0;k<6;k++)
					{
						a=sq[qh].x+fx[k];
						b=sq[qh].y+fy[k];
						c=sq[qh].z+fz[k];
						if(checkout( a, b, c)==1)
						{
							qe++;
							sq[qe].x=a;
							sq[qe].y=b;
							sq[qe].z=c;
								//printf(" <%d%d%d%d%d> ",a,b,c,qe,qh);
		
							sq[qe].pre=qh;
								//printf(" <%d%d%d%d%d> ",a,b,c,qe,sq[qe].pre);
							maze[a][b][c]=1;
							if(abc[a][b][c]=='E')
							{
								output();
								return 0;
							}
							

						}

					}
				}
	
	return 0;



}
int checkout(int a,int b,int c)
{
	if(a<0||a>L-1||b<0||b>R-1||c<0||c>C-1)
		return 0;
	if(abc[a][b][c]=='#'||maze[a][b][c]==1)
		return 0;
	return 1;
}
int output()
{
	int cout=0;bl=1;
	while(sq[qe].pre!=-1)
	{
		//printf(" %d ",qe);
		
		qe=sq[qe].pre;
		cout++;
		
	}
	//printf(" %d ",qe);
	//printf(" %d ",sq[qe].pre);
	printf("Escaped in %d minute(s).\n",cout);
	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