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 Jeymar at 2011-08-19 20:40:17 on Problem 2251
# include <iostream>
# include <string.h>
using namespace std;

char D[30][30][30]={0};
bool used[30][30][30];
int dx[6]={-1,0,0,0,0,1};
int dy[6]={0,-1,0,0,1,0};
int dz[6]={0,0,-1,1,0,0};
int l=0,r=0,c=0;
int sx,sy,sz,ex,ey,ez;
int time=0;

struct point 
{
	int x,y,z;
};

struct point qu[100000];

void bfs()
{
	int head=0,tail=0,head2=0,i=0;
	bool reach=false;
	memset(qu,0,sizeof(qu));
	qu[head].x=sx;
	qu[head].y=sy;
	qu[head].z=sz;
	head++;
    used[sx][sy][sz]=true;
	while(tail < head)
	{
		if(used[ex][ey][ez])
		{
            reach=true;
			break;
		}
        head2=head;
		time++;
		while(tail < head2)
		{
		    struct point tem1=qu[tail];
		    tail++;
	        for(i=0;i<6;i++)
			{
                struct point tem2;
		        tem2.x=tem1.x+dx[i];
                tem2.y=tem1.y+dy[i];
		        tem2.z=tem1.z+dz[i];
		        if(tem2.x>=0 && tem2.y>=0 && tem2.z>=0 && tem2.x<l && tem2.y<r && tem2.z<c && D[tem2.x][tem2.y][tem2.z] != '#' && !used[tem2.x][tem2.y][tem2.z])
				{
			        used[tem2.x][tem2.y][tem2.z]=true;
			        qu[head]=tem2;
			        head++;		   	   
				}		   
			}
		}
	}
    if(reach == false)
       time=-1;
}

int main()
{
   int i=0,j=0,k=0;
   while(scanf("%d%d%d",&l,&r,&c)!=EOF && l && r && c)
   {
	   memset(used,0,sizeof(used));
       
	   for(i=0;i<l;i++)
	   {
		   for(j=0;j<r;j++)
		   {
			   scanf("%s",D[i][j]);
		   }
	   }
	   for(i=0;i<l;i++)
	   {
		   for(j=0;j<r;j++)
		   {
			   for(k=0;k<c;k++)
			   {
				   if(D[i][j][k] == 'S')
				   {
					   sx=i;
					   sy=j;
					   sz=k;
				   }
				   else if(D[i][j][k] == 'E')
				   {
					   ex=i;
					   ey=j;
					   ez=k;
				   }
			   }
		   }
	   }
	   time=0;
	   bfs();
	   if(time==-1)
		   printf("Trapped!\n");
       else 
		   printf("Escaped in %d minute(s).\n",time);	   	   
   }
   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