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 del_juventus at 2009-02-16 15:25:47 on Problem 1979
#include"stdio.h"
void main()
{
    int i,j,p,q,m,n=0,n0=-1,step,a[2][100],b[2][100];
    char map[20][20];
    for(;;)
	{
	    scanf("%d %d%*c",&q,&p);
	    if(p==0 && q==0)break;
	    else
		{   step=0;
		    for(i=0;i<p;i++)
			{for(j=0;j<q;j++)
			   {scanf("%c",&map[i][j]);
			    if(map[i][j]=='@'){a[0][0]=i;a[1][0]=j;a[2][0]=0;step=1;}
			   }
			scanf("%*c");
			}
		    for(;;)
			{
			    for(m=0;m<=n;m++)
			       {i=a[0][m];j=a[1][m];
				if(i-1>=0 && map[i-1][j]=='.'){n0++;b[0][n0]=i-1;b[1][n0]=j;map[i-1][j]='@';step++;}
				if(i+1<p && map[i+1][j]=='.'){n0++;b[0][n0]=i+1;b[1][n0]=j;map[i+1][j]='@';step++;}
				if(j-1>=0 && map[i][j-1]=='.'){n0++;b[0][n0]=i;b[1][n0]=j-1;map[i][j-1]='@';step++;}
				if(j+1<q && map[i][j+1]=='.'){n0++;b[0][n0]=i;b[1][n0]=j+1;map[i][j+1]='@';step++;}
			       }
			    if(n0==-1){printf("%d\n",step);break;}
			    else
			       {n=n0;
				for(n0=0;n0<=n;n0++)
				   {a[0][n0]=b[0][n0];a[1][n0]=b[1][n0];}
				n0=-1;
			       }
			}
		}
	}
}

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