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

我不能发现错误啊,高手快来啊

Posted by xujiaming at 2008-07-09 16:03:19 on Problem 2251
这个代码我也测试过几个数据
都行啊
可还是WA
我用状态数组代替了队列
#include<stdio.h>
#include<stdlib.h>
int sum,l,r,h;
int arr[35][35][35],sign[35][35][35];
char s[35][35][35];
int f()
{
	int a,b,c,flag=0,flag1=0;
	sum++;
	for(a=0;a<l;a++)
	{
		for(b=0;b<r;b++)
		{
			for(c=0;c<h;c++)
				if(sign[a][b][c]==sum)
				{
					sign[a][b][c]=0;
						if(s[a-1][b][c]!='#'&&a>0&&arr[a-1][b][c]==0)
						{
							flag1=1;
							arr[a-1][b][c]=1;
							sign[a-1][b][c]=sum+1;	
							if(s[a-1][b][c]=='E')
							{
								flag=1;	
								flag1=0;
								break;
							}
							//printf("%d %d %d %d\n",a-1,b,c,sum);							
						}
						if(s[a+1][b][c]!='#'&&a+1<l&&arr[a+1][b][c]==0)
						{
							flag1=1;
							arr[a+1][b][c]=1;
							sign[a+1][b][c]=sum+1;
							if(s[a+1][b][c]=='E')
							{
								flag=1;	
								flag1=0;
								break;
							}
							//printf("%d %d %d %d\n",a+1,b,c,sum);	
						}
						if(s[a][b-1][c]!='#'&&b>0&&arr[a][b-1][c]==0)
						{
							flag1=1;
							arr[a][b-1][c]=1;
							sign[a][b-1][c]=sum+1;
							if(s[a][b-1][c]=='E')
							{
								flag=1;	
								flag1=0;
								break;
							}
							//printf("%d %d %d %d\n",a,b-1,c,sum);	
						}
						if(s[a][b+1][c]!='#'&&b+1<r&&arr[a][b+1][c]==0)
						{
							flag1=1;
							arr[a][b+1][c]=1;
							sign[a][b+1][c]=sum+1;
							if(s[a][b+1][c]=='E')
							{
								flag=1;	
								flag1=0;
								break;
							}
							//printf("%d %d %d %d\n",a,b+1,c,sum);	
						}
						if(s[a][b][c-1]!='#'&&c>0&&arr[a][b][c-1]==0)
						{
							flag1=1;
							arr[a][b][c-1]=1;
							sign[a][b][c-1]=sum+1;
							if(s[a][b][c-1]=='E')
							{
								flag=1;
								flag1=0;	
								break;
							}	
							//printf("%d %d %d %d\n",a,b,c-1,sum);
						}
						if(s[a][b][c+1]!='#'&&c+1<h&&arr[a][b][c+1]==0)
						{
							flag1=1;
							arr[a][b][c+1]=1;
							sign[a][b][c+1]=sum+1;
							if(s[a][b][c+1]=='E')
							{
								flag=1;	
								flag1=0;
								break;
							}	
							//printf("%d %d %d %d\n",a,b,c+1,sum);
						}	
				}
			if(flag)break;
		}
		if(flag)break;
	}
	if(flag1)flag=f();
	return flag;		
}
int main()
{
	int i,j,k,flag;
	while(1)
	{
		for(i=0;i<35;i++)
			for(j=0;j<35;j++)
				for(k=0;k<35;k++)
				{
					arr[i][j][k]=0;
					sign[i][j][k]=0;
				}
		scanf("%d%d%d",&l,&r,&h);
		if(l==0||r==0||h==0)break;
		getchar();
		for(i=0;i<l;i++)
		{
			for(j=0;j<r;j++)
			{
				scanf("%s",&s[i][j]);
				getchar();	
				//printf("%s\n",s[i][j]);
			}
			getchar();	
		}
		for(i=0;i<l;i++)
		{
			for(j=0;j<r;j++)
			{
				for(k=0;k<h;k++)
					if(s[i][j][k]=='S')
					{
						flag=1;
						break;
					}
				if(flag)break;
			}
			if(flag)break;
		}
		sum=0;
		arr[i][j][k]=1;
		sign[i][j][k]=1;
		flag=f();
		if(flag)printf("Escaped in %d minute(s).\n",sum);
		else 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