poj 3620 Avoid The Lakes
2015-08-04 19:50
288 查看
AvoidTheLakes
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
SampleOutput
TimeLimit:1000MS | MemoryLimit:65536K | |
TotalSubmissions:6959 | Accepted:3693 |
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;
}
相关文章推荐
- springMVC中的@RequestMapping的作用
- SDUToj2122数据结构实验之链表七:单链表中重复元素的删除
- hasLayout与Block formatting contexts的学习(下)
- 手势
- 手势Gesture
- ios圆角提高性能
- 二分法查找问题
- HDU 1543:Avoid The Lakes 【深搜】
- ios学习笔记--(oc基础3)
- In App Purchases 入门
- css3常用基础
- 常见版本控制器使用
- hdu1285(确定比赛名次)初学拓扑
- FZU 1752 A^B mod C
- VNC Viewer连接成功后闪退的解决办法
- 如何进行表的复制
- C++封装互斥量和条件变量
- android_error:R cannot be resolved to a variable
- String、StringBuffer与StringBuilder之间区别
- 第三周遗忘总结