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. OpenCV MFC 模块间通信

    1. 新建MFC项目 点击完成. 2. 添加按钮 在"工具箱"中找到"Button"控件,添加至界面:  2. 配置opencv, 添加colordetecto ...

  2. php 原理相关

    [PHP 运行方式(PHP SAPI介绍)] http://www.phpddt.com/php/php-sapi.html [PHP内核探索:从SAPI接口开始]http://www.nowamag ...

  3. Java Base64编码与图片互转

    import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import ...

  4. java基础之集合List-ArrayList、LinkedList、Vector的差别

    PS:本篇博客主要參考jdk的底层源代码.而非自己动手写代码. 请问ArrayList.LinkedList.Vector的差别 ①ArrayList底层实际上是採用数组实现的(而且该数组的类型的Ob ...

  5. zabbix windows angent安装:

    zabbix windows angent安装:1.下载zabbix agent for windows客户端,直接解压到C盘下.C:\zabbix 的目录015/04/21 11:16 <DI ...

  6. C# 零散笔记

    关于控件 控件实质就是一个类 属性中的Name就是它实例后的变量名 属性中的其他东西就是类中的变量或函数 例如: 可以直接通过Name.BackColor=Color.Yellow; 来直接操作控件的 ...

  7. RocketMQ与Kafka对比(18项差异)评价版

    此文是rocketmq作者vintage.wang所写,对于每项对比,后面都增加了我的观点,有不对的地方,请各位指出. 淘宝内部的交易系统使用了淘宝自主研发的Notify消息中间件,使用Mysql作为 ...

  8. jquery优化引发的思考

    无意间看到jquery优化的一个细节让我觉得不可思议记录一下.仅仅只是换个地方代码就能提高数倍的效率,带给我的不是个仅是个小技巧,而是一总编程思想,技术大牛往往是在细节上体现. 通过缓存最小化选择操作 ...

  9. spring入门:beans.xml不提示、别名、创建对象的三种方式

    spring的版本是2.5 一.beans.xml文件不提示 Location:spring-framework-2.5.6.SEC01\dist\resources\spring-beans-2.5 ...

  10. ScriptManager需要用到的JS

    <script type="text/javascript"> Sys.Application.add_load(function() { var form = Sys ...