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 yangyipeng_thought at 2015-10-08 18:08:53 on Problem 3620 and last updated at 2015-10-08 18:11:40
#include <iostream>
#include <cstdio>

using namespace std;

int a[105][105];
int n,m;

int dfs(int i,int j){
	if(i<1 || i>n || j<1 || j>n || !a[i][j])
		return 0;
	a[i][j]=false;
	return dfs(i+1,j)+dfs(i,j+1)+dfs(i-1,j)+dfs(i,j-1)+1;
}

int main(){
	int i,j,k,ans=0;
	
	cin>>n>>m>>k;
	while(k--){
		int x,y;
		cin>>x>>y;
		a[x][y]=true;
	}
	
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			if(a[i][j])
				ans=max(dfs(i,j),ans);
	
	cout<<ans<<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