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

疑问a 我的代码在杭电一次就AC啦,为什么在这里交这么多都过不了啊!!!

Posted by Xiao_Dragon at 2009-08-28 19:09:03 on Problem 2225
附代码:
/*
  Name: PKU_2225_Asteroid!_SS_F
  Copyright: PRIVATE!!!
  Author: LONGIXAOZHI
  Date: 28-08-09 14:37
  Description: 三维空间的迷宫问题 三维广搜 
  宇宙空间与许多的小行星,从一个空位置出发去一个地方,要求找到最短的路径,没有输出NO ROUT!
  因为只可以走上下左右前后,因此,
  方向坐标为step[6][3]= { {1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,1}};
  记录路径的长度 dist[x][y][z]; 记录走到空间(x,y,z); dist[x][y][z]=0; 表示该点已经走过;
  定义一个map[x][y][z]; 记录空间的状态,因为只有能走和不能走两个状态,因此可定义为一个bool数组;
  bests 定义最短的距离;单位为1;
*/
#include<iostream>
#include<string>
#include<queue>
using namespace std;
const int maxn=10;
bool map[maxn][maxn][maxn];  
int dist[maxn][maxn][maxn];
int step[6][3]={{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
struct Coor
{
	int x,y,z;
}s,e;
int n,bests;

void BFS()
{
	memset(dist,0,sizeof(dist));
	dist[s.x][s.y][s.z]=0;
	queue<int> Q;
	Q.push(s.x); Q.push(s.y); Q.push(s.z);
	Coor t1,t2;
	while(!Q.empty())
	{
		t1.x=Q.front(); Q.pop();
		t1.y=Q.front(); Q.pop();
		t1.z=Q.front(); Q.pop();
		if(t1.x == e.x && t1.y == e.y && t1.z == e.z)
		{
			if(dist[t1.x][t1.y][t1.z] < bests) bests=dist[t1.x][t1.y][t1.z];
		}
		for(int k=0; k<6; k++)
		{
			t2.x= t1.x + step[k][0];
			t2.y= t1.y + step[k][1];
			t2.z= t1.z + step[k][2]; 
			if(t2.x >= n || t2.x < 0 || t2.y >= n || t2.y < 0 || t2.z >= n || t2.z < 0) 
				continue;
			if(dist[t2.x][t2.y][t2.z] != 0 || map[t2.x][t2.y][t2.z] == 0 ) 
				continue;
			
			dist[t2.x][t2.y][t2.z]= dist[t1.x][t1.y][t1.z] + 1;
			Q.push(t2.x); Q.push(t2.y); Q.push(t2.z);
		}
	}
}

int main()
{   
	char str[maxn]; int i,j,k;
	while(scanf("%s%d",&str,&n)!=EOF)
	{
		for( k=0; k<n; k++)          
		{  
			for( i=0; i<n; i++)      
			{    
				scanf("%s",str);
				for( j =0; j<n; j++) 
				{   
					if(str[j] == 'X') 
						map[i][j][k]= 0;
					else 
						map[i][j][k]= 1;
				}
			}
		}
		scanf("%d%d%d",&s.x,&s.y,&s.z);
		scanf("%d%d%d",&e.x,&e.y,&e.z);
		scanf("%s",str);

		bests=1001;
		BFS();
		if(bests == 1001) 
			cout<<"NO ROUTE"<<endl;
		else
		  cout<<n<<" "<<bests<<endl;
	}
	return 0;
}
/*
Sample Input
START 1
O
0 0 0
0 0 0
END

START 3
OOO
OOO
OOO
XXX
XXX
XXO
OOO
OOO
OOO
0 0 0
0 0 2
END

START 3
OOO
OOO
OOO
XXX
XXO
XXX
OOO
OOO
OOO
0 0 0
0 0 2
END

START 3
XXX
XXX
XXX
OOO
OOO
OOO
XXX
XXX
XXX
0 0 1
2 2 1
END

START 5
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
XXXXX
XXOXX
XXXXX
XXXXX
XXXXX
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
0 0 0
4 4 4
END

Sample Output

1 0
3 10
NO ROUTE
3 4
NO ROUTE

Source

South Central USA 2001
*/


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