Avoid The Lakes--poj3620
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 7023 | Accepted: 3735 |
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<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int N,K,M,a,b,cot,best;
int map[][];
int mov[][]={,,,-,,,-,};
bool can(int x,int y)/判断能否符合条件
{
if(x<||x>=N||y<||y>=K||!map[x][y])
return false;
return true;
}
void dfs(int x,int y)//深搜
{
int xx,yy,i;
map[x][y]=;//标记走过
for(i=;i<;i++)
{
xx=x+mov[i][];
yy=y+mov[i][];
if(can(xx,yy))
{
cot++;
dfs(xx,yy);
}
}
}
int main()
{
int i,j;
while(scanf("%d%d%d",&N,&K,&M)!=EOF)
{
memset(map,,sizeof(map));
for(i=;i<M;i++)
{
scanf("%d%d",&a,&b);
map[a-][b-]=;
}
int sum=;
best=;
for(i=;i<N;i++)
for(j=;j<K;j++)
{
cot=;
if(map[i][j])
{
dfs(i,j);
}
best=best>cot?best:cot;//更新最优解
}
printf("%d\n",best);
}
return ;
}
Avoid The Lakes--poj3620的更多相关文章
- [深度优先搜索] 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】
Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6795 Accepted: 3622 D ...
- Avoid The Lakes
Avoid The Lakes Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) To ...
- 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(广搜,简单)
题目 找最大的一片湖的面积,4便有1边相连算相连,4角不算. runtime error 有一种可能是 数组开的太小,越界了 #define _CRT_SECURE_NO_WARNINGS #incl ...
- 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 ...
- DFS:POJ3620-Avoid The Lakes(求最基本的联通块)
Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Description Farmer John's farm was flooded i ...
随机推荐
- c#实现生产者消费者模式
; } Environment.ExitCode = result; } }}
- wordpress教程之函数site_url()、home_url()、bloginfo(‘url’)的区别
在wordpress插件和主题开发中经常需要获取各种URL路径,wordpress提供了以下集中方法获得URL路径: plugins_url() — 插件目录的 URL (例如:http://www. ...
- Keil C51 Data Overlaying
一般的编译器将函数中的区域变数动态配置在stack,等函数结束空间就释放出来.因为8051 的内部记忆体很少,只有区区128 或256 bytes,而且stack 也是共用这块记忆体.为了节省stac ...
- QObject就有eventFilter,功能很强(随心所欲的进行处理,比如用来QLineEdit分词)
相信大家都用过词典吧!因为英语不太好...O(∩_∩)O~,所以经常进行划词翻译! 简述 实现 效果 源码 更多参考 实现 原理:鼠标移至某单词之上,获取鼠标位置,然后在对应位置进行取词,翻译! 基于 ...
- 用JSTL简化Java Web开发
如今这个手中的项目jstl都不要,不方便呢... 链接学习下载:http://c20000001.blog.163.com/blog/static/1154754120088303531450/
- 转:C# 中的委托和事件
引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容易了,而没有过去 ...
- find -exec
find -exec 的标准写法 find ./ -name "*.tmp" -exec rm -rf "{}" \; find -exec 这个命令组合很好用 ...
- Linux系统下定时上传文件至FTP服务器脚本
环境:Red Hat Enterprise Linux Server release 6.4 需求:需要将Oracle数据库的定时备份上传至FTP服务器 1.干货,用户名:oracle,数据库名称:X ...
- PHP - 多维数组
多维数组指的是包含一个或多个数组的数组. PHP 能理解两.三.四或五级甚至更多级的多维数组.不过,超过三级深的数组对于大多数人难于管理. 注释:数组的维度指示您需要选择元素的索引数. 对于二维数组, ...
- Unity 为自己组件添加公共方法
为什么需要跟你的组件添加公共方法呢? 留一条后路嘛,万一你那天想起要给全部的组件添加一个方法. 此时我只能告诉你慢慢修改吧累死你 子组件:A ,父组件:B继承方式: A -> B –> ...