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. Bootstrap_列表组

     一.基本列表组 列表组是Bootstrap框架新增的一个组件,可以用来制作列表清单.垂直导航等效果,也可以配合其他的组件制作出更漂亮的组件. <ul class="list-grou ...

  2. kali/centos 更新 java

    kali 转自:http://blog.sina.com.cn/s/blog_5736d8870102w15u.html 墙内的论坛上和博客上有很多这样的文章了,不过一般过程都很复杂,让人看的头晕眼花 ...

  3. .NET4.5 WFP中用WebBrowser获取/操作网页html代码

    引言 想给自己之前写的网页小说爬虫程序更新换代,之前一直是用winform的形式写的程序,因此这一次更新打算把UI换成WPF(因为听说WPF很漂亮),顺便也以此引入WPF的学习. 那么作为网页爬虫程序 ...

  4. 编辑距离——Edit Distance

    编辑距离 在计算机科学中,编辑距离是一种量化两个字符串差异程度的方法,也就是计算从一个字符串转换成另外一个字符串所需要的最少操作步骤.不同的编辑距离中定义了不同操作的集合.比较常用的莱温斯坦距离(Le ...

  5. solr 3.5.0 与 tomcat 7.0.5 整合配置

    1.将D:\software\lucene-3.6.0\apache-solr-3.5.0\example\solr下的文件拷贝到要作为服务器的位置(如:D:\lucene\solr\home),可以 ...

  6. CSS3动画特效——transform详解

    transform让css3可以做很优质的特效,transform的意思是:改变,使-变形,转换. 在css3中transform的作用也是改变,让元素倾斜,旋转,缩放,位移. 下面来一一分解tran ...

  7. WinForm中MouseEnter和MouseLeave混乱的问题

    MouseEnter+MouseLeave不行,我用了MouseMove+MouseLeave,效果一样 最近做个聊天的系统,仿照qq的界面设计,像qq聊天界面中字体.表情.截图等图片,鼠标放上去显示 ...

  8. String All Methods

    1.public char charAt(int index) public class Test{ public static void main(String args[]){ String s= ...

  9. mac系统安装node

    1.node 是通过brew来安装的,所以第一步先安装brew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebre ...

  10. IOS开发之GCD---dispatch_semaphore

     信号量是一个整形值并且具有一个初始计数值,并且支持两个操作:信号通知和等待.当一个信号量被信号通知,其计数会被增加.当一个线程在一个信号量上等待时,线程会被阻塞(如果有必要的话),直至计数器大于零, ...