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

高手看一下,我的BFS哪错了??我的测试数据都对呀!!!

Posted by byron at 2006-07-12 21:07:04 on Problem 2251
#include <stdio.h>
#include <string.h>

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

POS move[7];

POS from,end,now,next;
POS queue[35*30*30];
int front,rear;
bool maze[35][35][35];
int L,R,C;
char p;
int i,j,k;
int v;
int count;
void main()
{
	freopen("1.txt","r",stdin);
	move[1].x=-1;
	move[1].y=0;
	move[1].z=0;
	move[2].x=0;
	move[2].y=-1;
	move[2].z=0;
	move[3].x=0;
	move[3].y=0;
	move[3].z=1;
	move[4].x=0;
	move[4].y=1;
	move[4].z=0;
	move[5].x=0;
	move[5].y=0;
	move[5].z=-1;
	move[6].x=1;
	move[6].y=0;
	move[6].z=0;
	scanf("%d%d%d",&L,&R,&C);
	while(L!=0 && R!=0 && C!=0)
	{
		memset(maze,1,sizeof(bool)*35*35*35);
		count=-1;
		scanf("%c",&p);
		for(i=1;i<=L;i++)
		{
			for(j=1;j<=R;j++)
			{
				for(k=1;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);
		}

		front=rear=1;
		queue[rear].x=from.x;
		queue[rear].y=from.y;
		queue[rear].z=from.z;
		maze[from.x][from.y][from.z]=1;
		while(front<=rear)
		{
			now.x=queue[front].x;
			now.y=queue[front].y;
			now.z=queue[front].z;
			count++;
			for(v=1;v<=6;v++)
			{
				next.x=now.x+move[v].x;
				next.y=now.y+move[v].y;
				next.z=now.z+move[v].z;
				if(!maze[next.x][next.y][next.z])
				{
					rear++;
					queue[rear].x=next.x;
					queue[rear].y=next.y;
					queue[rear].z=next.z;
					maze[next.x][next.y][next.z]=1;
					if(next.x==end.x && next.y==end.y && next.z==end.z)	
					{
						count--;
						goto	LL;
					}
				}
			}
			front++;
		}

		if(front>rear)
			printf("Trapped!\n");
		else
LL:			printf("Escaped in %d minute(s).\n",count);
		scanf("%d%d%d",&L,&R,&C);
	}
}

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