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

哪位大牛棒忙看看DFS做的,测试数据对,可就是wa,,写了一晚了,郁闷!

Posted by yan3276 at 2007-09-12 21:45:43 on Problem 2251
#include <cstdlib>
#include <iostream>

using namespace std;
 struct ELEMENT
  {
	 int x,y,z,dir;
  };
 ELEMENT move[6]={{1,0,0},
              {0,1,0},
              {-1,0,0},
              {0,-1,0},
              {0,0,1},
              {0,0,-1}
              };
 ELEMENT from,end,now,next;
 ELEMENT Stack[32*32*32];
 int top,flag;
 int front,rear;
 int maze[35][35][35];
 int L,R,C;
 char p;
int main(int argc, char *argv[])
{   int count;
    int i,j,k,v;
	scanf("%d%d%d",&L,&R,&C);
	while(L!=0 && R!=0 && C!=0)
	{  flag=0;
       memset(maze,1,sizeof(maze));		
        scanf("%c",&p);
		for(i=0;i<L;i++)
		{
			for(j=0;j<R;j++)
			{
				for(k=0;k<C;k++)
				{
					scanf("%c",&p);
					if(p=='#')
						maze[i][j][k]=1;
					else if(p=='.')
						maze[i][j][k]=0;
					else if(p=='S')
					{
						maze[i][j][k]=0;
						from.x=i;
						from.y=j;
						from.z=k;
					}
					else if(p=='E')
					{
						maze[i][j][k]=0;
						end.x=i;
						end.y=j;
						end.z=k;
					}
				}
				scanf("%c",&p);
			}
			scanf("%c",&p);
		}				
		top=-1;
        Stack[++top].x=from.x;
		Stack[top].y=from.y;
		Stack[top].z=from.z;
		Stack[top].dir=-1;	
		while(top!=-1)
		{   if(flag==1) break;
			now.x=Stack[top--].x;
			now.y=Stack[top].y;
			now.z=Stack[top].z;
			v=Stack[top].dir+1;          	
			while(v<6)
			 {	                
                next.x=now.x+move[v].x;
				next.y=now.y+move[v].y;
				next.z=now.z+move[v].z;			
				if(next.x>=0&&next.x<L&&next.y>=0&&next.y<R&&next.z>=0&&next.z<C)
				{  
				   if(!maze[next.x][next.y][next.z]&&next.x==end.x&&next.y==end.y&&next.z==end.z)
				     {   printf("Escaped in %d minute(s).\n",top);
				         flag=1;
                         break;
                     } 
                    if(!maze[next.x][next.y][next.z])
			         { top++;
				       Stack[top].x=next.x;
		 	           Stack[top].y=next.y;
				       Stack[top].z=next.z;
				       Stack[top].dir=v;				     
				       maze[next.x][next.y][next.z]=2;
				       now.x=next.x;
				       now.y=next.y;
				       now.z=next.z;
				       v=-1;                    					
				     }
                 }
				v++;
			 }			
         }
    if(flag==0) printf("Trapped!\n");
   	scanf("%d%d%d",&L,&R,&C);
  }
    system("PAUSE");
    return EXIT_SUCCESS;
}

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