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的更多相关文章

  1. [深度优先搜索] POJ 3620 Avoid The Lakes

    Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8173   Accepted: 4270 D ...

  2. poj 3620 Avoid The Lakes【简单dfs】

    Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6795   Accepted: 3622 D ...

  3. POJ 3620 Avoid The Lakes【DFS找联通块】

    Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6826   Accepted: 3637 D ...

  4. poj 3620 Avoid The Lakes(广搜,简单)

    题目 找最大的一片湖的面积,4便有1边相连算相连,4角不算. runtime error 有一种可能是 数组开的太小,越界了 #define _CRT_SECURE_NO_WARNINGS #incl ...

  5. POJ 3620 Avoid The Lakes(dfs算法)

    题意:给出一个农田的图,n行m列,再给出k个被淹没的坐标( i , j ).求出其中相连的被淹没的农田的最大范围. 思路:dfs算法 代码: #include<iostream> #inc ...

  6. 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 ...

  7. Avoid The Lakes

    Avoid The Lakes Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) To ...

  8. poj 3620

    题意:给出一个矩阵,其中有些格子干燥.有些潮湿. 如果一个潮湿的格子的相邻的四个方向有格子也是潮湿的,那么它们就可以构成更大 的湖泊,求最大的湖泊. 也就是求出最大的连在一块儿的潮湿的格子的数目. # ...

  9. POJ 3620 DFS

    题意: 给你n*m的矩形,有k个坏点 问最大坏点连通块的坏点数. 一发水题.. 裸的DFS // by SiriusRen #include <cstdio> #include <a ...

随机推荐

  1. JAVA 运用流编程实现简单的"记事本"功能

    一.概要 1.功能介绍 2.实现的思路及步骤代码 3.完整代码 二.功能 运用IO流和Swing实现简单的记事本功能(打开.保存.退出) 三.思路及实现步骤 1.在构造函数中画出操作界面 //创建jt ...

  2. AJPFX关于集合的几种变量方式

    package com.java.test; import java.util.ArrayList;import java.util.Enumeration;import java.util.Iter ...

  3. DLL入门浅析【转】

     1.建立DLL动态库 动态链接库(DLL)是从C语言函数库和Pascal库单元的概念发展而来的.所有的C语言标准库函数都存放在某一函数库中.在链接应用程序的过程中,链接器从库文件中拷贝程序调用的函数 ...

  4. 洛谷 P1030 求先序排列

    题目描述 给出一棵二叉树的中序与后序排列.求出它的先序排列.(约定树结点用不同的大写字母表示,长度<=8). 输入输出格式 输入格式: 2行,均为大写字母组成的字符串,表示一棵二叉树的中序与后序 ...

  5. systemtap执行过程中报probe timer.profile registration error

    probe timer.profile registration error 今天在执行火焰图的过程中,代码报错,probe timer.profile registration error 经过查询 ...

  6. windows快捷键cmd中

    windows 中cmd中命令: cls  ---------> 清屏 dir ----------> 获取目录 Ctrl + c ----> 结束当前命令 cd .. ------ ...

  7. Mathematics-基础:斐波那契数列

    f(1)=1 f(2)=1 f(n)=f(n-1)+f(n-2) n>2

  8. QT+常见控件+tab Widget 和Stacked Widget

    首先:这里介绍以下tab Widget 和Stacked Widget 之间的区别和使用的方法: tab Widget控件可以直接的进行切换,Stacked Widget却不可以直接在界面上进行切换, ...

  9. 【2019-5-26】python:字典、常用字符串处理方法及文件操作

    一.数据类型:字典 1.字典: 1.1定义字典:dict={'key':'value'} 1.2字典与列表相比,字典取值快,可直接找到key 1.3字典是无序的,不能根据顺序取值 1.4多个元素用逗号 ...

  10. vue2.0中transition组件的用法

    作用:实现元素进入/离开的过渡效果. 首先,让我们举个栗子: <!DOCTYPE html> <html lang="en"> <head> & ...