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 zou1120655 at 2011-07-29 21:50:26 on Problem 2251
#include<iostream>
using namespace std;
int D[6][3]={{1,0,0},{0,1,0},{0,0,1},{-1,0,0},{0,-1,0},{0,0,-1}};
struct sq{ 
	int x,y,z;  
	int t;      
};
char maze[31][31][31];
int L,R,C;
int bfs(int x,int y,int z){  
	int front=0,tail=1; 
	sq node[10000];              
	node[0].x=x;node[0].y=y;node[0].z=z;   
	node[0].t=0;   
	while(front<tail)
	{   
		for(int h=0;h<6;h++) 
		{    
			int i=node[front].x+D[h][0];              
			int j=node[front].y+D[h][1];      
			int k=node[front].z+D[h][2];     
			if(maze[i][j][k]=='E') 	return node[front].t+1;            
			if(i>=0&&i<L&&j>=0&&j<R&&k>=0&&k<C&&maze[i][j][k]!='#') 
			{      
				node[tail].x=i; 
				node[tail].y=j;
				node[tail].z=k;    
				node[tail++].t=node[front].t+1;    
				maze[i][j][k]='#';     
			}                         
		}      
		front++;        
	}  
	return -1;
}
int main()
{   
	while(1)
	{   
		int bx=0,by=0,bz=0;  
		cin>>L>>R>>C;    
		if(L==0&&R==0&&C==0) exit(0);  
		for(int i=0;i<L;i++)    
			for(int j=0;j<R;j++)  
				for(int k=0;k<C;k++) 
				{        
					cin>>maze[i][j][k];    
					if(maze[i][j][k]=='S')   
					{         
						bx=i;by=j;bz=k;  
					}     
				}      
				int total=bfs(bx,by,bz);   
				if(total!=-1) cout<<"Escaped in "<<total<<" minute(s)."<<endl;     
				else cout<<"Trapped!"<<endl;     
	}    	   
	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