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

1562过了,这题自己测试很多数据都对,但是WA,帮我看下吧~

Posted by qq_lqy at 2009-05-12 15:44:26 on Problem 2386
#include <stdio.h>

void lakecount(char a[100][100],int f[100][100],int i,int j,int n,int m)
{
	if(i>=0&&i<n&&j>=0&&j<m&&f[i][j]==-1&&a[i][j]=='W')
	{
		f[i][j]=1;
		lakecount(a,f,i-1,j-1,n,m);
		lakecount(a,f,i-1,j,n,m);
		lakecount(a,f,i-1,j+1,n,m);
		lakecount(a,f,i,j-1,n,m);
		lakecount(a,f,i,j+1,n,m);
		lakecount(a,f,i+1,j-1,n,m);
		lakecount(a,f,i+1,j,n,m);
		lakecount(a,f,i+1,j+1,n,m);
	}
}
void main()
{
	int num=0,line,col,i,j,flag[100][100];
	char str[100][100];
	scanf("%d%d",&line,&col);
	for(i=0;i<line;i++)
		scanf("%s",str[i]);
	for(i=0;i<line;i++)
		for(j=0;j<col;j++)
			flag[i][j]=-1;
	for(i=0;i<line;i++)
		for(j=0;j<col;j++)
		{
			if(flag[i][j]==-1&&str[i][j]=='W')
			{
				num++;
				lakecount(str,flag,i,j,line,col);
			}
		}
	printf("%d\n",num);

}

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