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 Hammer307 at 2009-04-16 18:59:40 on Problem 3620
#include <iostream>
using namespace std;
int a[101][101],r,c,i,j,k;
int f(int x,int y)
{
	if(x<1||x>r||y<1||y>c||a[x][y]==0)
		return 0;
	a[x][y]=0;
	return 1+f(x-1,y)+f(x+1,y)+f(x,y-1)+f(x,y+1);
}
int main()
{
	cin>>r>>c>>k;
	while(k--){
			//scanf("%d%d",&i,&j);
			cin>>i>>j;
			a[i][j]=1;
	}
	int max=-1,s;
	for(i=1;i<=r;i++)
		for(j=1;j<=c;j++){
			if(a[i][j])
				s=f(i,j);
			if(max<s)
				max=s;
		}
	cout<<max<<endl;
	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