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

Re:求0s代码

Posted by scau_200930740601 at 2010-07-17 21:43:53 on Problem 2251
In Reply To:求0s代码 Posted by:kirsten0302 at 2009-11-18 13:39:17
#include<stdio.h>
int bfs[30000][3];
char data[50][50][50];
int i,j,k,sum[50][50][50],level,n,m,si,sj,sk,ei,ek,ej,bfs_num,ok,l;
main()
{
	while(1)
	{
		memset(sum,0,sizeof(sum));
		memset(data,0,sizeof(data));
		scanf("%d%d%d",&level,&n,&m);
		if((level==0)&&(level==n)&&(level==m))
			break;
		for(i=0;i<level;i++)
			for(j=0;j<n;j++)
				scanf("%s",data[i][j]);
		for(i=0;i<level;i++)
			for(j=0;j<n;j++)
				for(k=0;k<m;k++)
					if(data[i][j][k]=='S')
					{
						bfs[0][0]=i;bfs[0][1]=j;bfs[0][2]=k;l=0;
					}
					else if(data[i][j][k]=='E')
					{
						ei=i;ej=j;ek=k;
					}
	    bfs_num=0;ok=0;
		while(bfs_num<=l)
		{
			for(i=0;i<6;i++)
			{
				if((i==0)&&(bfs[bfs_num][0]+1<level))
				{
					if(((data[bfs[bfs_num][0]+1][bfs[bfs_num][1]][bfs[bfs_num][2]]=='.')||(data[bfs[bfs_num][0]+1][bfs[bfs_num][1]][bfs[bfs_num][2]]=='E'))&&(sum[bfs[bfs_num][0]+1][bfs[bfs_num][1]][bfs[bfs_num][2]]==0))
					{
						l++;
						bfs[l][0]=bfs[bfs_num][0]+1;
						bfs[l][1]=bfs[bfs_num][1];
						bfs[l][2]=bfs[bfs_num][2];
						sum[bfs[l][0]][bfs[l][1]][bfs[l][2]]=sum[bfs[bfs_num][0]][bfs[bfs_num][1]][bfs[bfs_num][2]]+1;
						if((bfs[l][0]==ei)&&(bfs[l][1]==ej)&&(bfs[l][2]==ek))
						{
							ok=1;break;
						}
					}
				}
				else if((i==1)&&(bfs[bfs_num][0]-1>=0))
				{
					if(((data[bfs[bfs_num][0]-1][bfs[bfs_num][1]][bfs[bfs_num][2]]=='.')||(data[bfs[bfs_num][0]-1][bfs[bfs_num][1]][bfs[bfs_num][2]]=='E'))&&(sum[bfs[bfs_num][0]-1][bfs[bfs_num][1]][bfs[bfs_num][2]]==0))
					{
						l++;
						bfs[l][0]=bfs[bfs_num][0]-1;
						bfs[l][1]=bfs[bfs_num][1];
						bfs[l][2]=bfs[bfs_num][2];
						sum[bfs[l][0]][bfs[l][1]][bfs[l][2]]=sum[bfs[bfs_num][0]][bfs[bfs_num][1]][bfs[bfs_num][2]]+1;
						if((bfs[l][0]==ei)&&(bfs[l][1]==ej)&&(bfs[l][2]==ek))
						{
							ok=1;break;
						}
					}
				}
				else if((i==2)&&(bfs[bfs_num][1]+1<n))
				{
					if(((data[bfs[bfs_num][0]][bfs[bfs_num][1]+1][bfs[bfs_num][2]]=='.')||(data[bfs[bfs_num][0]][bfs[bfs_num][1]+1][bfs[bfs_num][2]]=='E'))&&(sum[bfs[bfs_num][0]][bfs[bfs_num][1]+1][bfs[bfs_num][2]]==0))
					{
						l++;
						bfs[l][0]=bfs[bfs_num][0];
						bfs[l][1]=bfs[bfs_num][1]+1;
						bfs[l][2]=bfs[bfs_num][2];
						sum[bfs[l][0]][bfs[l][1]][bfs[l][2]]=sum[bfs[bfs_num][0]][bfs[bfs_num][1]][bfs[bfs_num][2]]+1;
						if((bfs[l][0]==ei)&&(bfs[l][1]==ej)&&(bfs[l][2]==ek))
						{
							ok=1;break;
						}
					}
				}
				else if((i==3)&&(bfs[bfs_num][1]-1>=0))
				{
					if(((data[bfs[bfs_num][0]][bfs[bfs_num][1]-1][bfs[bfs_num][2]]=='.')||(data[bfs[bfs_num][0]][bfs[bfs_num][1]-1][bfs[bfs_num][2]]=='E'))&&(sum[bfs[bfs_num][0]][bfs[bfs_num][1]-1][bfs[bfs_num][2]]==0))
					{
						l++;
						bfs[l][0]=bfs[bfs_num][0];
						bfs[l][1]=bfs[bfs_num][1]-1;
						bfs[l][2]=bfs[bfs_num][2];
						sum[bfs[l][0]][bfs[l][1]][bfs[l][2]]=sum[bfs[bfs_num][0]][bfs[bfs_num][1]][bfs[bfs_num][2]]+1;
						if((bfs[l][0]==ei)&&(bfs[l][1]==ej)&&(bfs[l][2]==ek))
						{
							ok=1;break;
						}
					}
				}
				else if((i==4)&&(bfs[bfs_num][2]+1<m))
				{
					if(((data[bfs[bfs_num][0]][bfs[bfs_num][1]][bfs[bfs_num][2]+1]=='.')||(data[bfs[bfs_num][0]][bfs[bfs_num][1]][bfs[bfs_num][2]+1]=='E'))&&(sum[bfs[bfs_num][0]][bfs[bfs_num][1]][bfs[bfs_num][2]+1]==0))
					{
						l++;
						bfs[l][0]=bfs[bfs_num][0];
						bfs[l][1]=bfs[bfs_num][1];
						bfs[l][2]=bfs[bfs_num][2]+1;
						sum[bfs[l][0]][bfs[l][1]][bfs[l][2]]=sum[bfs[bfs_num][0]][bfs[bfs_num][1]][bfs[bfs_num][2]]+1;
						if((bfs[l][0]==ei)&&(bfs[l][1]==ej)&&(bfs[l][2]==ek))
						{
							ok=1;break;
						}
					}
				}
				else if((i==5)&&(bfs[bfs_num][2]-1>=0))
				{
					if(((data[bfs[bfs_num][0]][bfs[bfs_num][1]][bfs[bfs_num][2]-1]=='.')||(data[bfs[bfs_num][0]][bfs[bfs_num][1]][bfs[bfs_num][2]-1]=='E'))&&(sum[bfs[bfs_num][0]][bfs[bfs_num][1]][bfs[bfs_num][2]-1]==0))
					{
						l++;
						bfs[l][0]=bfs[bfs_num][0];
						bfs[l][1]=bfs[bfs_num][1];
						bfs[l][2]=bfs[bfs_num][2]-1;
						sum[bfs[l][0]][bfs[l][1]][bfs[l][2]]=sum[bfs[bfs_num][0]][bfs[bfs_num][1]][bfs[bfs_num][2]]+1;
						if((bfs[l][0]==ei)&&(bfs[l][1]==ej)&&(bfs[l][2]==ek))
						{
							ok=1;break;
						}
					}
				}
			}
			if(ok==1)
			{
				printf("Escaped in %d minute(s).\n",sum[bfs[l][0]][bfs[l][1]][bfs[l][2]]);break;
			}
			bfs_num++;
		}
		if(ok==0)
			printf("Trapped!\n");
	}
}

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