Avoid The Lakes

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 190   Accepted Submission(s) : 106
Problem Description

Farmer John's farm was flooded in the most recent storm, a fact only aggravated by the information that his cows are deathly afraid of water. His insurance agency will only repay him, however, an amount depending on the size of the largest "lake" on his farm.

The farm is represented as a rectangular grid with N (1 ≤ N ≤ 100) rows and M (1 ≤ M ≤ 100) columns. Each cell in the grid is either dry or submerged, and exactlyK (1 ≤ K ≤ N × M) of the cells are submerged. As one would expect, a lake has a central cell to which other cells connect by sharing a long edge (not a corner). Any cell that shares a long edge with the central cell or shares a long edge with any connected cell becomes a connected cell and is part of the lake.

 
Input

* Line 1: Three space-separated integers: NM, and K
* Lines 2..K+1: Line i+1 describes one submerged location with two space separated integers that are its row and column: R and C

 
Output

* Line 1: The number of cells that the largest lake contains. 

 
Sample Input
3 4 5
3 2
2 2
3 1
2 3
1 1
 
Sample Output
4
 题解:相当于水池数目那题,只不过这个是找最大的水的个数;
代码:
 #include<stdio.h>
#include<string.h>
int N,M,max,step;
int map[][];
void dfs(int x,int y){
    if(!map[x][y]||x<||x>=N||y<||y>=M)return;
    map[x][y]=;step++;
    if(step>max)max=step;
    dfs(x+,y);dfs(x-,y);dfs(x,y+),dfs(x,y-);
//    step--;map[x][y]=1;
    return;
}
int main(){
    int K,x,y;
    while(~scanf("%d%d%d",&N,&M,&K)){
        memset(map,,sizeof(map));
        while(K--){
            scanf("%d%d",&x,&y);
            map[x-][y-]=;
        }
        max=step=;
        for(x=;x<N;x++){
            for(y=;y<M;y++){//printf("%d ",map[x][y]);
                if(map[x][y])step=,dfs(x,y);
            }//puts("");
        }
        printf("%d\n",max);
    }
    return ;
}

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. POJ 3620 Avoid The Lakes

    http://poj.org/problem?id=3620 DFS 从任意一个lake出发 重置联通的lake 并且记录 更新ans #include <iostream> #inclu ...

  8. Avoid The Lakes--poj3620

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

  9. DFS:POJ3620-Avoid The Lakes(求最基本的联通块)

    Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Description Farmer John's farm was flooded i ...

随机推荐

  1. curl 浏览器模拟请求实战

    1,curl 常用选项

  2. FWA winner | Car Visualizer WebGL

    FWA winner | Car Visualizer WebGL Car Visualizer made in WebGL using ThreeJS. It requires a modern b ...

  3. 文件系统、mkdir、touch、nano、cp笔记

    文件系统:rootfs: 根文件系统 FHS:Linux发行版目录层级遵循协议 /boot: 系统启动相关的文件,如内核.initrd,以及grub(bootloader)引导加载器/dev: 设备文 ...

  4. poj 3370 Halloween treats(鸽巢原理)

    Description Every year there is the same problem at Halloween: Each neighbour is only willing to giv ...

  5. Linux 下的php,nginx,mysql的安装

    yum -y install wget make vim install gcc gcc-c++ ncurses ncurses-devel autoconf libjpeg libjpeg-deve ...

  6. iOS 苹果app提交 ITC.apps.validation.prerelease_build_missing

    提示这信息,由于没有选择包文件, 在提交页面以下bulid的区域, 加入你的app就可以 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYWxpbmNleG ...

  7. Win8 使用VC6.0调试

    Win8.1下无法执行vc++6.0的解决方法 注意 安装过程中最后一步会卡在那里不动,能够直接关闭安装程序,忽略报错. 1 安装完毕后在安装文件夹下找到MSDEV.EXE 而且将 MSDEV.EXE ...

  8. linux下tar.xz 文件解压

    在linux下下载源码文件安装时有些会遇到tar.xz文件的解压,习惯了tar解压缩,第一次遇到.xz文件还是有点迷惑,google 如下,解压这种格式的文件需要xz工具,如果xz工具没有安装,则安装 ...

  9. JAVA HashMap与HashTable 区别

    HashTable和HashMap区别 第一,继承不同. public class Hashtable extends Dictionary implements Mappublic class Ha ...

  10. spring boot1.3.0版本及以上版本profile指定参数无法被打入

    现象:小于1.3.0版本如1.2.6的spring boot, 当指定profile进行参数打入的时候,发现没有问题,但是比如改用1.3.0,1.3.1及其以上版本的时候,发现参数打不进去,经过比对s ...