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

大神的提示祝我一臂之力:附代码 记得清空队列,数组开31可过

Posted by jinhouyu at 2015-06-19 08:54:51 on Problem 2251
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
int visit[41][41][41];
char map[41][41][41];
struct node
{
	int x,y,z;
	int s;
};
queue<node> q;
int main()
{
	int l,r,c,i,j,k,flag;
	char ch;
	while(1)
	{
		node start;
		scanf("%d%d%d",&l,&r,&c);
		if(l==0&&r==0&&c==0)	break;
		memset(map,'.',sizeof(map));
		getchar();
		for(i=0;i<l;i++)
		{	for(j=0;j<r;j++)
			{	for(k=0;k<c;k++)
				{
					ch=getchar();
					map[i][j][k]=ch;
					if(ch=='S')	
					{
						start.x=i;
						start.y=j;
						start.z=k;
						start.s=0;
					}
				}
				getchar();
			}
			getchar();
		}
		while(!q.empty())
			q.pop();
		memset(visit,0,sizeof(visit));
			
			q.push(start);
			visit[start.x][start.y][start.z]=1;
			flag=1;
		while(!q.empty())
		{
			node m=q.front();
			q.pop();
			if(map[m.x][m.y][m.z]=='E')
			{
				printf("Escaped in %d minute(s).\n",m.s);
				flag=0;
				break;
			}
			m.s++;
			node m2;
			if(m.x-1>=0)
			{
				m2=m;
				m2.x--;
				if(visit[m2.x][m2.y][m2.z]==0&&map[m2.x][m2.y][m2.z]!='#')
				{	visit[m2.x][m2.y][m2.z]=1;
					q.push(m2);	
				}		
			}
			if(m.x+1<l)
			{
				m2=m;
				m2.x++;
				if(visit[m2.x][m2.y][m2.z]==0&&map[m2.x][m2.y][m2.z]!='#')
				{	visit[m2.x][m2.y][m2.z]=1;
					q.push(m2);	
				}		
			}
			if(m.y-1>=0)
			{
				m2=m;
				m2.y--;
				if(visit[m2.x][m2.y][m2.z]==0&&map[m2.x][m2.y][m2.z]!='#')
				{	visit[m2.x][m2.y][m2.z]=1;
					q.push(m2);	
				}		
			}
			if(m.y+1<r)
			{
				m2=m;
				m2.y++;
				if(visit[m2.x][m2.y][m2.z]==0&&map[m2.x][m2.y][m2.z]!='#')
				{	visit[m2.x][m2.y][m2.z]=1;
					q.push(m2);	
				}		
			}
			if(m.z-1>=0)
			{
				m2=m;
				m2.z--;
				if(visit[m2.x][m2.y][m2.z]==0&&map[m2.x][m2.y][m2.z]!='#')
				{	visit[m2.x][m2.y][m2.z]=1;
					q.push(m2);	
				}		
			}
			if(m.z+1<c)
			{
				m2=m;
				m2.z++;
				if(visit[m2.x][m2.y][m2.z]==0&&map[m2.x][m2.y][m2.z]!='#')
				{	visit[m2.x][m2.y][m2.z]=1;
					q.push(m2);	
				}		
			}
		}	
		if(flag)	
		  puts("Trapped!");	
	}	
	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