POJ 3620 Avoid The Lakes
http://poj.org/problem?id=3620
DFS
从任意一个lake出发
重置联通的lake 并且记录 更新ans
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std; int N,M,K;
bool pool[][];
int d[][] = {-, , , , , , , -};
int res = ;
int ans = ;
bool OK(int x, int y)
{
if (x < || x > N || y < || y > M) return false;
return pool[x][y];
}
void dfs(int x, int y)
{
res++;
pool[x][y] = false;
int nx, ny;
for (int i = ; i < ; i++)
{
nx = x+d[i][];
ny = y+d[i][];
if ( OK(nx, ny) )
{
dfs(nx, ny);
}
}
}
int main()
{ while (cin >> N >> M >> K)
{
memset(pool, , sizeof(pool));
for (int i = ; i < K; i++)
{
int r, c;
scanf("%d%d", &r, &c);
pool[r][c] = true;
}
res = ;
ans = ;
for (int i = ; i <= N; i++)
for (int j = ; j <= M; j++)
{
if (OK(i, j))
{
res = ;
dfs(i, j);
}
ans = max(ans, res);
}
cout << ans << endl;
}
return ;
}
POJ 3620 Avoid The Lakes的更多相关文章
- [深度优先搜索] 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 ...
- 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 ...
- Avoid The Lakes
Avoid The Lakes Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) To ...
- poj 3620
题意:给出一个矩阵,其中有些格子干燥.有些潮湿. 如果一个潮湿的格子的相邻的四个方向有格子也是潮湿的,那么它们就可以构成更大 的湖泊,求最大的湖泊. 也就是求出最大的连在一块儿的潮湿的格子的数目. # ...
- POJ 3620 DFS
题意: 给你n*m的矩形,有k个坏点 问最大坏点连通块的坏点数. 一发水题.. 裸的DFS // by SiriusRen #include <cstdio> #include <a ...
随机推荐
- canvas基础绘制-倒计时(上)
效果: html: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- Openrisc的or1200
1 什么是OpenRISC OpenRISC 是硬件开源社区opencores开发的RISC指令集处理器架构,包括32 bits 的Openrisc1000 和64 bitsOpenrisc 2000 ...
- JS正则匹配待重命名文件名
<script>var str = "123 - Copy(2).csv";var regExp = /^123( - Copy(\(\d+\))?)?.csv$/;d ...
- LINUX 安装tsung 对OPENFIRE 进行压力测试
参考资料: http://www.centoscn.com/image-text/install/2014/0818/3503.html http://my.oschina.net/jieluck ...
- xcode uml 工具
https://github.com/PaulTaykalo/objc-dependency-visualizer ./generate-objc-dependencies-to-json.rb -d ...
- Mysql is not allowed to connect mysql server
1. mysql -u root -p 2. select host from user where user='root'; //可以看到当前主机配置信息为localhost ...
- Linux-fuser
Linux-fuser 1. 描述 2. 选项3. EXAMPLES4. RESTRICTIONS 限制5. SIGNAL 可用信号 fuser - 使用文件或套接字识别进程 1. 描述 fuser使 ...
- 远程桌面mstsc关闭连接栏
在进行mstsc远程桌面连接电脑或者虚拟机的时候,总是会出现一个连接栏.虽然点左边的图钉可以自动隐藏,但是每次鼠标滑到上面的时候,还是会冒出来,这个就有点烦心了. 查了下资料,解决了这个问题. 关闭步 ...
- CF550 DIV3
A - Diverse Strings CodeForces - 1144A A string is called diverse if it contains consecutive (adjace ...
- Centos7中yum安装jdk及配置环境变量
系统版本 [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) #安装之前先查看一下有无系统 ...