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

求高手看看我为什么老是WA啊~

Posted by joan333 at 2011-08-01 10:10:26 on Problem 2251
discuss里的数据也过了~
队列也清空了~就是不知道为什么老是WA啊~
#include"iostream"
#include"queue"
#include"cstdio"
#include"cstring"
using namespace std;
struct NODE
{
	char a;
	int length;
	int x,y,z;
} map[35][35][35],temp,start,tex;
int i,j,k;
queue<NODE>Que;
bool visited[35][35][35];
int L,R,C;
int s[6][3]={{1,0,0},{0,1,0},{0,0,1},{-1,0,0},{0,-1,0},{0,0,-1}};
int bfs()
{
	while(!Que.empty())
		Que.pop();
	memset(visited,false,sizeof(visited));
		for(k=0;k<L;k++)
			for(j=0;j<R;j++)
				for(i=0;i<C;i++)
	if(map[i][j][k].a=='S')
	{	
		start=map[i][j][k];
		start.x=i;
		start.y=j;
		start.z=k;
		Que.push(start);
		visited[i][j][k]=true;
		start.length=0;
		break;
	}
	for(;;)
	{
		temp=Que.front();
		Que.pop();
		temp.a=map[temp.x][temp.y][temp.z].a;
		for(i=0;i<6;i++)
		{
			tex.x=temp.x+s[i][0];
			tex.y=temp.y+s[i][1];
			tex.z=temp.z+s[i][2];
			if(map[tex.x][tex.y][tex.z].a=='.'&&visited[tex.x][tex.y][tex.z]==false)
			{
				tex.length=temp.length+1;
				visited[tex.x][tex.y][tex.z]=true;
				Que.push(tex);
			}
			if(map[tex.x][tex.y][tex.z].a=='E')
				return temp.length+1;
		}
		if(Que.empty())
		return temp.length;	
	}	
}
int main()
{
	int tt;
	while(scanf("%d%d%d",&L,&R,&C),L!=0)
	{
		for(k=0;k<L;k++)
			for(j=0;j<R;j++)
				for(i=0;i<C;i++)
					scanf(" %c",&map[i][j][k].a);
		
		tt=bfs();
		if(tt!=0)
		printf("Escaped in %d minute(s).\n",tt);
		else
		printf("Trapped!\n");
		for(k=0;k<L;k++)
			for(j=0;j<R;j++)
				for(i=0;i<C;i++)
				map[i][j][k].a='#';
	}
	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