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 TSERROF at 2012-09-28 13:29:18 on Problem 2251
#include<iostream>
#include <cstring>
#include <queue>
using namespace std;
char map[55][55][55];
int step[55][55][55];
typedef struct coordinate
{
	int x,y,l;
}coor;
queue<coor> searchline;
int BFS(int i,int j,int k)
{
	coor C;
	C.x=i;
	C.y=j;
	C.l=k;
	searchline.push(C);
	while(!searchline.empty())
	{
		coor temp=searchline.front();
		searchline.pop();
		if(map[temp.x][temp.y][temp.l]=='E') return step[temp.x][temp.y][temp.l];
		if(map[temp.x-1][temp.y][temp.l]!='#' && !step[temp.x-1][temp.y][temp.l])
		{
			coor t(temp);
			--t.x;
			searchline.push(t);
			step[t.x][t.y][t.l]=step[temp.x][temp.y][temp.l]+1;
		}
		if(map[temp.x+1][temp.y][temp.l]!='#' && !step[temp.x+1][temp.y][temp.l])
		{
			coor t(temp);
			++t.x;
			searchline.push(t);
			step[t.x][t.y][t.l]=step[temp.x][temp.y][temp.l]+1;
		}
		if(map[temp.x][temp.y-1][temp.l]!='#' && !step[temp.x][temp.y-1][temp.l])
		{
			coor t(temp);
			--t.y;
			searchline.push(t);
			step[t.x][t.y][t.l]=step[temp.x][temp.y][temp.l]+1;
		}
		if(map[temp.x][temp.y+1][temp.l]!='#' && !step[temp.x][temp.y+1][temp.l])
		{
			coor t(temp);
			++t.y;
			searchline.push(t);
			step[t.x][t.y][t.l]=step[temp.x][temp.y][temp.l]+1;
		}
		if(map[temp.x][temp.y][temp.l-1]!='#' && !step[temp.x][temp.y][temp.l-1])
		{
			coor t(temp);
			--t.l;
			searchline.push(t);
			step[t.x][t.y][t.l]=step[temp.x][temp.y][temp.l]+1;
		}
		if(map[temp.x][temp.y][temp.l+1]!='#' && !step[temp.x][temp.y][temp.l+1])
		{
			coor t(temp);
			++t.l;
			searchline.push(t);
			step[t.x][t.y][t.l]=step[temp.x][temp.y][temp.l]+1;
		}
	}
	return -1;
}
int main()
{
	int L,R,C;
	while(cin>>L>>R>>C && (L || R ||C ))
	{
		while(!searchline.empty())searchline.pop();
		memset(map,'#',sizeof(map));
		memset(step,0,sizeof(step));
		int s_i,s_j,s_l,e_i,e_j,e_l;
		for(int k=1;k<=L;++k)
		{
			for(int i=1;i<=R;++i)
			{
				for(int j=1;j<=C;++j)
				{ 
					cin>>map[i][j][k];
					if(map[i][j][k]=='S')s_i=i,s_j=j,s_l=k;
					if(map[i][j][k]=='E')e_i=i,e_j=j,e_l=k;
				}
			}
		}
		int ans=BFS(s_i,s_j,s_l);
		if(ans==-1)cout<<"Trapped!"<<endl;
		else cout<<"Escaped in "<<ans<<" minute(s)."<<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