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 ...
随机推荐
- AJPFX总结方法里的属性
嵌套循环:循环里套循环 假设外循环的循环次数是m次,内循环的循环次数是n次,那么内层循环的循环次数需要 m * n次. Eg:利用for循环语句的嵌套打印出乘法口诀表 class break1 ...
- AJPFX的内存管理小结
管理范围:任何继承于 NSObject的对象原理:每一个对象都有引用计数器当使用alloc new 和 copy创建对象时引用计数器被设置为1给对象发送一条retain消息 ,引用计数器加1 ...
- logging日志过滤和日志文件自动截取
1.日志过滤 import logging class IgnoreFilter(logging.Filter): def filter(self,record): return "girl ...
- Android Platform Version 和 API Level对照
Platform Version API Level VERSION_CODE Notes Android 5.1 22 LOLLIPOP_MR1 Platform Highlights Androi ...
- Tomcat配置Oracle数据源
开发环境:Eclipse luna.tomcat 7.Oracle 配置Oracle datasource步骤 第一步:打开tomcat目录下的 context.xml 文件,添加 Resource ...
- linux截图工具
推荐:deepin-scrot 满足功能: 能够自定义快捷键(Ctrl+Alt+A) 小巧快速自定义选择区域进行截图 有简单的绘图功能 可以快速的保存到剪切版(双击图片) P.S.:双重截图
- Git理论知识补充
转自: http://www.cnblogs.com/hnrainll/archive/2012/11/13/2768003.html 对于任何一个文件,在 Git 内都只有三种状态:已提交(comm ...
- varchar2(100 char)是什么意思
最佳答案 varchar2(100 char)最长可以插入100个任意字符而varchar2(100)最长可以插入100个英文字符
- 面向对象的设计的SOLID原则
S.O.L.I.D是面向对象设计和编程中5个重要编码规则的首字母的缩写. - SRP The Single Responsibility Principle 单一责任原则 当需要修改某个类的时候原因有 ...
- 小程序08 小程序访问服务器API
后台交互 小程序是前端框架,需要和后台交互,本次课程主要介绍网络API. 小程序提供的网络访问API wx.request接口 发起 HTTPS 网络请求. 使用rqeust接口前的工作 1.小程序需 ...