您的位置:首页 > 其它

poj 3620 Avoid The Lakes

2015-08-04 19:50 288 查看
AvoidTheLakes

TimeLimit:1000MSMemoryLimit:65536K
TotalSubmissions:6959Accepted:3693
Description

FarmerJohn'sfarmwasfloodedinthemostrecentstorm,afactonlyaggravatedbytheinformationthathiscowsaredeathlyafraidofwater.Hisinsuranceagencywillonlyrepayhim,however,anamountdependingonthesize
ofthelargest"lake"onhisfarm.

ThefarmisrepresentedasarectangulargridwithN(1≤N≤100)rowsand
M(1≤M≤100)columns.Eachcellinthegridiseitherdryorsubmerged,andexactly
K(1≤K≤N×M)ofthecellsaresubmerged.Asonewouldexpect,alakehasacentralcelltowhichothercellsconnectbysharingalongedge(notacorner).Anycellthatsharesalongedgewiththecentralcellorshares
alongedgewithanyconnectedcellbecomesaconnectedcellandispartofthelake.

Input

*Line1:Threespace-separatedintegers:N,
M,andK

*Lines2..K+1:Linei+1describesonesubmergedlocationwithtwospaceseparatedintegersthatareitsrowandcolumn:
RandC

Output

*Line1:Thenumberofcellsthatthelargestlakecontains. 

SampleInput
345
32
22
31
23
11


SampleOutput
4


代码:


#include<stdio.h>
intn,m,k,sum;
intr,c;
inta[110][110]={0};
intdfs(intx,inty)
{
if(x>=1&&x<=n&&y>=1&&y<=m&&a[x][y]==1)
{
sum++;
a[x][y]=0;
dfs(x+1,y);
dfs(x-1,y);
dfs(x,y-1);
dfs(x,y+1);
}
}
intmain()
{
inti,j,max=0;
scanf("%d%d%d",&n,&m,&k);
while(k--)
{
scanf("%d%d",&r,&c);
a[r][c]=1;
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(a[i][j]!=0)
{
sum=0;
dfs(i,j);
if(sum>max)
max=sum;
}
}
}
printf("%d\n",max);
return0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: