poj 3620 Avoid The Lakes【简单dfs】
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 6795 | Accepted: 3622 |
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
/*
题意:给出你湖的坐标,让你求最大的湖的大小(湖的大小是从这个点的四个方向中有一个方向
仍然为湖,即小湖可以组成大湖)
题解:先将给出的坐标储存下来并标记,其余的点记为0,
跟hdu1241做法一样,只不过此题只需要搜索四个方向
*/
#include<stdio.h>
#include<string.h>
#define MAX 110
#define maxn(x,y)(x>y?x:y)
int map[MAX][MAX];
int tot,max,n,m;
void dfs(int x,int y)
{
int i,j;
int move[4][2]={0,1,0,-1,1,0,-1,0};
if(x>0&&x<=n&&y>0&&y<=m&&map[x][y]==1)
{
tot++;//记录这个湖的大小
map[x][y]=0;
for(i=0;i<4;i++)//四个方向查找
{
dfs(x+move[i][0],y+move[i][1]);
}
}
}
int main()
{
int k,r,c,t,i,j;
memset(map,0,sizeof(map));
scanf("%d%d%d",&n,&m,&k);
for(i=1;i<=k;i++)
{
scanf("%d%d",&r,&c);
map[r][c]=1;
}
max=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(map[i][j]==1)
{
tot=0;
dfs(i,j);//搜索一遍之后tot的值就是当前搜索的湖的大小
max=maxn(max,tot);//找到最大的湖
}
}
}
printf("%d\n",max);
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: 6826 Accepted: 3637 D ...
- POJ 3620 Avoid The Lakes(dfs算法)
题意:给出一个农田的图,n行m列,再给出k个被淹没的坐标( i , j ).求出其中相连的被淹没的农田的最大范围. 思路:dfs算法 代码: #include<iostream> #inc ...
- [深度优先搜索] 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(广搜,简单)
题目 找最大的一片湖的面积,4便有1边相连算相连,4角不算. runtime error 有一种可能是 数组开的太小,越界了 #define _CRT_SECURE_NO_WARNINGS #incl ...
- 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 1979 Red and Black (简单dfs)
题目: 简单dfs,没什么好说的 代码: #include <iostream> using namespace std; typedef long long ll; #define IN ...
- poj 2386:Lake Counting(简单DFS深搜)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18201 Accepted: 9192 De ...
- Avoid The Lakes
Avoid The Lakes Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) To ...
随机推荐
- JPEG 图
多媒体教程 - JPEG 图 JPEG 是在 Web 上使用的主要图像格式之一. 本文讲解 JPEG 图像的概念和特性. 理解图像格式 无论是 HTML 还是 XHTML 都没有规定图像的官方格式.然 ...
- node exports和module.exports区别
我们只需知道三点即可知道 exports 和 module.exports 的区别了: exports 是指向的 module.exports 的引用 module.exports 初始值为一个空对象 ...
- 配置并学习微信JS-SDK(2)—扫一扫接口http://www.qq210.com/shoutu/android
http://www.qq210.com/shoutu/android //c_开头的js变量是服务器传过来的 var c_access_token = "<?=$access_tok ...
- Linux进程和进程边界
1. 进程和线程 2. 手机操作系统的发展 3. 进程的地址空间边界 4. 进程边界的安全围栏: Crash的不可扩延性 5. 进程边界的安全围栏: 全局数据和服务的不可访问性 http://www. ...
- SqlHelper 帮助文档及详解--项目初步搭建
微软SqlHelper类中文注释和使用方法 相关链接: http://blog.csdn.net/itmaxin/article/details/7609566 SqlHelper.cs是N年前微软出 ...
- [BZOJ 3564] [SHOI2014] 信号增幅仪 【最小圆覆盖】
题目链接:BZOJ - 3564 题目分析 求最小椭圆覆盖,题目给定了椭圆的长轴与 x 轴正方向的夹角,给定了椭圆长轴与短轴的比值. 那么先将所有点旋转一个角度,使椭圆长轴与 x 轴平行,再将所有点的 ...
- nodejs compressor
http://www.2cto.com/kf/201203/122015.html http://www.cnblogs.com/terrylin/archive/2013/06/01/3112596 ...
- Ubuntu版本介绍
转自Ubuntu版本介绍 经常有人问起Ubuntu的版本选择问题,论坛中虽有帖子提及,但不是很详细,不集中,我就尝试把Ubuntu上的这点东东翻译一下,供大家参考,水平有限,敬请包涵.指正. Ubu ...
- 监控 DNS 流量,预防安全隐患五大招!
尽管 IT 管理员尽心尽责地监控设备.主机和网络是否存在恶意活动的迹象,却往往出力不讨好.主机入侵检测和端点保护对很多公司来说可能是"必需"的安全措施,但如果要找出 RAT.roo ...
- 如何通过js使搜索关键词高亮
给你推荐通过jquery来实现高亮关键词.jquery.textSearch-1.0.js代码: (function($){ $.fn.textSearch =function(str,options ...