Avoid The Lakes
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8173   Accepted: 4270

Description

Farmer John's farm was flooded in the most recent storm, a fact only aggravated by the information that his cows are deathly afraid of water. His insurance agency will only repay him, however, an amount depending on the size of the largest "lake" on his farm.

The farm is represented as a rectangular grid with N (1 ≤ N ≤ 100) rows and M (1 ≤ M ≤ 100) columns. Each cell in the grid is either dry or submerged, and exactly K (1 ≤ K ≤ N × M) of the cells are submerged. As one would expect, a lake has a central cell to which other cells connect by sharing a long edge (not a corner). Any cell that shares a long edge with the central cell or shares a long edge with any connected cell becomes a connected cell and is part of the lake.

Input

* Line 1: Three space-separated integers: NM, and K
* Lines 2..K+1: Line i+1 describes one submerged location with two space separated integers that are its row and column: R and C

Output

* Line 1: The number of cells that the largest lake contains. 

Sample Input

3 4 5
3 2
2 2
3 1
2 3
1 1

Sample Output

4

Source

 
原题大意: 给张地图,然后看看最大连通的面积。
解题思路: 快到新生赛了,每天刷两道水题。DFS
 
#include<stdio.h>
int map[120][120],ans,n,m,squ,max;
const int dx[2][4]={{0,0,1,-1},{1,-1,0,0}};
void dfs(int x,int y)
{
int i,xx,yy;
for(i=0;i<4;++i)
{
xx=x+dx[0][i];yy=y+dx[1][i];
if(xx>0&&yy>0&&xx<=n&&yy<=m&&map[xx][yy])
{
map[xx][yy]=0;
++squ;
dfs(xx,yy);
}
}
return ;
}
int main()
{
int k,i,j;
scanf("%d%d%d",&n,&m,&k);
while(k--)
{
scanf("%d%d",&i,&j);
map[i][j]=1;
}
for(i=1;i<=n;++i)
for(j=1;j<=m;++j)
if(map[i][j])
{
squ=1;
map[i][j]=0;
dfs(i,j);
max=max<squ?squ:max;
}
printf("%d\n",max);
return 0;
}

  

[深度优先搜索] POJ 3620 Avoid The Lakes的更多相关文章

  1. poj 3620 Avoid The Lakes【简单dfs】

    Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6795   Accepted: 3622 D ...

  2. POJ 3620 Avoid The Lakes【DFS找联通块】

    Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6826   Accepted: 3637 D ...

  3. POJ 3620 Avoid The Lakes

    http://poj.org/problem?id=3620 DFS 从任意一个lake出发 重置联通的lake 并且记录 更新ans #include <iostream> #inclu ...

  4. poj 3620 Avoid The Lakes(广搜,简单)

    题目 找最大的一片湖的面积,4便有1边相连算相连,4角不算. runtime error 有一种可能是 数组开的太小,越界了 #define _CRT_SECURE_NO_WARNINGS #incl ...

  5. POJ 3620 Avoid The Lakes(dfs算法)

    题意:给出一个农田的图,n行m列,再给出k个被淹没的坐标( i , j ).求出其中相连的被淹没的农田的最大范围. 思路:dfs算法 代码: #include<iostream> #inc ...

  6. POJ 3620 Avoid The Lakes (求连接最长的线)(DFS)

    Description Farmer John's farm was flooded in the most recent storm, a fact only aggravated by the i ...

  7. [深度优先搜索] POJ 1426 Find The Multiple

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28550   Accepted: 118 ...

  8. POJ 3009 深度优先搜索

    问题:打冰球.冰球可以往上下左右4个方向走,只有当冰球撞到墙时才会停下来,而墙会消失.当冰球紧贴墙时,不能将冰球往那个方向打.冰球出界就当输,超过10次还没将冰球打到目标位置也当输.求用最小次数将冰球 ...

  9. 深度优先搜索初尝试-DFS-LakeCounting POJ No.2386

    DFS入门的一道经典题目:LakeCounting 用栈或队列来实现: #include<cstdio> #include<stdlib.h> #include<iost ...

随机推荐

  1. 自定义圆饼(利用贝塞尔曲线和CGContext类完成)

    -(void)drawRect:(CGRect)rect{ CGFloat w = self.bounds.size.width; CGFloat h = self.bounds.size.heigh ...

  2. 使用 Laravel 前的准备工作

    是的,使用 Laravel 前需要准备开发环境,准备工作做完后,就可以一门心思的投入到学习 Laravel 知识的战斗中去了. Larvavel 是一个 PHP 框架,API 非常语义化.它激进,使用 ...

  3. 【分享】图解Windows Server 2012 R2 配置IIS 8全过程

    最近计划更换服务器,包括IIS服务器与数据库服务器,操作系统都是Windows Server 2012 R2,第一次接触Windows Server 2012,感觉比较新鲜,一路摸索完成了IIS 8 ...

  4. .NET WebBroswer内存释放

    最近写的小说爬取工具遇到了性能瓶颈,使用多个Webbroswer控件预加载多个网页,内存会不断增加,达到400M左右,不能忍. 失败的例子 首先尝试把Webbroswer对象置为null,wb=nul ...

  5. 《与小卡特一起学Python》Code1

    print "I love pizza!" print "pizza " * 20 print "yum " * 40 print &quo ...

  6. [原]Linux ssh远程连接断开问题处理办法

    我们在通过远程连接操作Linux server的时候,有可能过一段时间忘记操作,便会发生ssh断开的问题. 而如果是本地的server,比较好办,直连设备kill掉ssh,踢掉无效用户连接,再次链接即 ...

  7. Rdlc报表 数据汇总分组展示

    1.从工具箱拉出表或者矩阵(本次使用的是矩阵) 2.选择需要的数据集,没有就新建一个数据集,名称自己起好,下面有用到 3.将行组和行列显示出来(右击报表--试图=>) 4.双击行组下的RowGr ...

  8. “static”引发的一个错误

    昨天晚上,舍友发来一个程序,先把代码贴上:  #include<stdio.h>#define N 20short bufferA[N]={1,2,3,4,5,6,7,8,9,10,11, ...

  9. jQuery index()

    index() index() 方法返回指定元素相对于其他指定元素的 index 位置. 语法 $(selector1).index(selector2) selector2:可选,指定元素:为空时默 ...

  10. :target伪类制作tab选项卡

    :target伪类的作用是突出显示活动的HTML锚,下面是一个简单的例子: HTML代码: <div> <a href="#demo1">点击此处</ ...