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

I got AC

Posted by suby at 2005-12-18 09:01:12 on Problem 2312
#include <stdio.h>
char map[310][310];
int a[310][310];
int main()
{
	int n,m,i,j,tx,ty;
	while(scanf("%d %d",&n,&m)!=EOF)
	{
		if(n==0 && m==0)
			break;
		map[0][0]=map[n+1][0]=map[0][m+1]=map[n+1][m+1]=3;
		for(i=1;i<=n;i++)
		{
			map[i][0]=map[i][m+1]=3;
			scanf("%s",map[i]+1);
			
			for(j=1;j<=m;j++)
			{
				if(map[i][j]=='Y')
				{
					a[i][j]=0;
					map[i][j]=1;
				}
				else
				{
					a[i][j]=1000000000;
					if(map[i][j]=='T')
					{
						map[i][j]=1;
						tx=i;
						ty=j;
					}
					else if(map[i][j]=='E')
					{
						map[i][j]=1;
					}
					else if(map[i][j]=='B')
					{
						map[i][j]=2;
					}
					else if(map[i][j]=='R')
					{
						map[i][j]=3;
					}
					else if(map[i][j]=='S')
					{
						map[i][j]=3;
					}
				}
			}
		}
		for(i=1;i<=n;i++)
		{
			map[0][i]=map[n+1][i]=3;
		}
		while(-1)
		{
			int temp=0;
			for(i=1;i<=n;i++)
			{
				for(j=1;j<=m;j++)
				{
					if(a[i][j]<1000000000)
					{
						if(map[i-1][j]<3 && a[i-1][j]>a[i][j]+map[i-1][j])
						{
							a[i-1][j]=a[i][j]+map[i-1][j];
							temp=1;
						}
						if(map[i+1][j]<3 && a[i+1][j]>a[i][j]+map[i+1][j])
						{
							a[i+1][j]=a[i][j]+map[i+1][j];
							temp=1;
						}
						if(map[i][j-1]<3 && a[i][j-1]>a[i][j]+map[i][j-1])
						{
							a[i][j-1]=a[i][j]+map[i][j-1];
							temp=1;
						}
						if(map[i][j+1]<3 && a[i][j+1]>a[i][j]+map[i][j+1])
						{
							a[i][j+1]=a[i][j]+map[i][j+1];
							temp=1;
						}
					}
				}
			}if(temp==0)
			{
				break;
			}
		}
		if(a[tx][ty]<1000000000)
		{
			printf("%d\n",a[tx][ty]);
		}
		else
			printf("-1\n");
	}

	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