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. windows 查看某端口被占用情况

    百度经验 http://jingyan.baidu.com/article/3c48dd34491d47e10be358b8.html 基本命令 netstat -ano

  2. java实现斐波那契的两种方法

    package com.ywx.count; /** * 斐波那契数列(地推方式要比递归方式的效率要高) * @author Vashon(yangwenxue) * date:20150320 */ ...

  3. Js学习文件上传

    // 文件上传 jQuery(function() { var $ = jQuery, $list = $('#thelist'), $btn = $('#ctlBtn'), state = 'pen ...

  4. BZOJ 2157: 旅游 (2017.7.21 6:30-2017.7.21 15:38 今日第一题。。)

    Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 1754  Solved: 765 Description Ray 乐忠于旅游,这次他来到了T 城.T ...

  5. COGS 942. [東方S3] 比那名居天子

    Problem 1 比那名居天子(tenshi.cpp/c/pas) 题目描述 在幻想乡,比那名居天子是管理着『要石』的天人.『要石』是能够引发和镇压地震的存在,当然也可以用来改变地形.因为在幻想乡引 ...

  6. JAVA自带的加密算法-MD5\SHA1\BASE64

    需要导入jar包: commons-codec.jar MD5 String str = "abc"; DigestUtils.md5Hex(str); SHA1 String s ...

  7. MATLAB GUI制作快速入门

    创建空白的GUI在MATLAB命令行中输入guide新建GUI,选择Blank GUI (Default),点击确定后就生成了一个空白的GUI制作界面,如下图所示 图1制作GUI的具体过程简单加法器将 ...

  8. Microsoft Project 2010基础使用方法

    5.1 项目管理与Microsoft Project2010 Microsoft Project2010深受广大项目管理工程师的青睐. 5.1.1 项目管理的概念 项目管理是项目管理者在有限的资源约束 ...

  9. GCC、g++编译器和gcc编译器的区别

    GCC:(GNU Compiler Collection,GNU编译器套件),是由 GNU 开发的编程语言编译器.它是以GPL许可证所发行的自由软件,也是 GNU计划的关键部分. gcc:GNU的C语 ...

  10. ping ip

    def ip_and_time(): """ get ip to ping from ip.txt then return two list , each ip that ...