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 ...
随机推荐
- 牛人cad二次开发网站(.net)
http://through-the-interface.typepad.com/through_the_interface/autocad_net/ http://through-the-inter ...
- 网页尺寸scrollHeight/offsetHeight
scrollHeight和scrollWidth,获取网页内容高度和宽度. 一.针对IE.Opera: scrollHeight 是网页内容实际高度,可以小于 clientHeight. 二.针对NS ...
- 【学习笔记】深入理解js闭包
本文转载: 一.变量的作用域 要理解闭包,首先必须理解Javascript特殊的变量作用域. 变量的作用域无非就是两种:全局变量和局部变量. Javascript语言的特殊之处,就在于函数内部可以直接 ...
- Android开发精品收藏贴
各种下拉刷新效果: https://github.com/scwang90/SmartRefreshLayout
- TFS2010升级至TFS2013完全指南(更换服务器)
一.背景: 公司已使用tfs2010很长时间,目前随着公司的发展,项目越来越少,而产品越来越多,采用的开发模式,也逐渐从瀑布式.迭代式转向敏捷开发.为了更好的支持产品研发,决定将tfs ...
- react基础语法(五) state和props区别和使用
props的验证: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...
- 洛谷 P1030 求先序排列
题目描述 给出一棵二叉树的中序与后序排列.求出它的先序排列.(约定树结点用不同的大写字母表示,长度<=8). 输入输出格式 输入格式: 2行,均为大写字母组成的字符串,表示一棵二叉树的中序与后序 ...
- 【C++】cerr,cout,clog
http://stackoverflow.com/questions/16772842/what-is-the-difference-between-cout-cerr-clog-of-iostrea ...
- 阿里P7/P8学习路线图——技术封神之路
一.基础篇 JVM JVM内存结构 堆.栈.方法区.直接内存.堆和栈区别 Java内存模型 内存可见性.重排序.顺序一致性.volatile.锁.final 垃圾回收 内存分配策略.垃圾收集器(G1) ...
- Django 你需要了解的入门操作
创建一个django project (我的版本是1.11.11) django-admin startproject mysite cd mysite 当前目录下会生成mysite的工程,目录结 ...