poj--3620--Avoid The Lakes(dfs)
| Time Limit: 1000MS | Memory Limit: 65536KB | 64bit IO Format: %I64d & %I64u |
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: N, M, 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
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int map[1010][1010];
int n,m,s,ans,maxx;
void dfs(int x,int y)
{
if(x<1||x>n||y<1||y>m||map[x][y]==0)
return ;
map[x][y]=0;
ans++;
dfs(x+1,y);
dfs(x-1,y);
dfs(x,y+1);
dfs(x,y-1);
}
int main()
{
while(scanf("%d%d%d",&n,&m,&s)!=EOF)
{
int x,y;
maxx=0;
memset(map,0,sizeof(map));
for(int i=0;i<s;i++)
{
scanf("%d%d",&x,&y);
map[x][y]=1;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(map[i][j])
{
ans=0;
dfs(i,j);
maxx=max(ans,maxx);
}
}
}
printf("%d\n",maxx);
}
return 0;
}
poj--3620--Avoid The Lakes(dfs)的更多相关文章
- poj 3620 Avoid The Lakes【简单dfs】
Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6795 Accepted: 3622 D ...
- POJ 3620 Avoid The Lakes【DFS找联通块】
Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6826 Accepted: 3637 D ...
- [深度优先搜索] POJ 3620 Avoid The Lakes
Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8173 Accepted: 4270 D ...
- POJ 3620 Avoid The Lakes(dfs算法)
题意:给出一个农田的图,n行m列,再给出k个被淹没的坐标( i , j ).求出其中相连的被淹没的农田的最大范围. 思路:dfs算法 代码: #include<iostream> #inc ...
- 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 ...
- POJ 3620 Avoid The Lakes
http://poj.org/problem?id=3620 DFS 从任意一个lake出发 重置联通的lake 并且记录 更新ans #include <iostream> #inclu ...
- poj 3620 Avoid The Lakes(广搜,简单)
题目 找最大的一片湖的面积,4便有1边相连算相连,4角不算. runtime error 有一种可能是 数组开的太小,越界了 #define _CRT_SECURE_NO_WARNINGS #incl ...
- Avoid The Lakes
Avoid The Lakes Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) To ...
- POJ 1321-棋盘问题(DFS 递归)
POJ 1321-棋盘问题 K - DFS Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I6 ...
随机推荐
- COGS——T 2739. 凯伦和咖啡
http://www.cogs.pro/cogs/problem/problem.php?pid=2739 ★★☆ 输入文件:coffee.in 输出文件:coffee.out 简单对比时 ...
- HDU 4303 Contest 1
说实话,挺复杂的一道题. 我采用栈的方式,DFS在搜索完一个节点的所有子结点后,通过排序,加快计算该结点所有可能的路径:子结点与子结点的连通,子结点与父结点的连通,通过父结点与各祖先结点的连通.同时记 ...
- Oracle性能分析1:开启SQL跟踪和获取trace文件
当Oracle查询出现效率问题时,我们往往须要了解问题所在,这样才干针对问题给出解决方式.Oracle提供了SQL运行的trace信息,当中包括了SQL语句的文本信息.一些运行统计,处理过程中的等待, ...
- iOS Autolayout情况下,ViewController嵌套时,childViewController的Frame异常问题
近期项目中,使用Storyboard.AutoLayout开发,某个ViewController中嵌套了多个子ViewController,结果在将其加入到父ViewController时,出现坐标异 ...
- 具体解释XML解析(一)—解析接口浅析
在DRP项目中接触到了一个XML解析工具DOM4J,它作为解析工具的据说性能很优秀.可是刚刚接触解析工具不久,而且也没有使用过其它的解析工具.因此对于DOM4J的性能没有直接的感受(没有參照物).只是 ...
- 为powerpc交叉编译nginx
HOST: MINT NGINX VERSION: nginx-1.8.0(nginx-1.8.0.tar.gz) ZLIB VERSION: zlib-1.2.8 PCRE VERSION: pcr ...
- ubuntu 下的文件校验(md5、sha256)
在本地使用 md5sum/sha256sum 生成某待测文件的 hash 值,以跟标准文件的 hash 值做对比验证,确定经网络传输过程得到的文件是否真实无损.一般而言,hash 值如果一致,大概率上 ...
- 联想E490 加M.2固态硬盘 卡在第一画面不动解决办法
电脑配置: E490 500G机械硬盘,自己加M.2 NVMe 固态硬盘. 问题:启动时出现 2101:Detection error on SSD1(M.2), 无法识别到机械硬盘 (重新插拨 ...
- [国家集训队]最长双回文串 (PAM)回文自动机
Code: // luogu-judger-enable-o2 #include <cstdio> #include <algorithm> #include <cstr ...
- 获取鼠标经过处的标签的标签名和id
<script> var el = window.document.body; // 声明一个变量,默认值为body window.document.body.onmouseover = ...