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. 用Python实现九九乘法表

    1.用“#”组成的矩形的实现 代码 eight = int(input("Height:")) #用户输入高度 width = int(input("Width:&quo ...

  2. cocos2dx 3.1从零学习(三)——Touch事件(回调,反向传值)

    第三讲 Touch 前面两篇我们学习的内容,足够我们做一款简单的小游戏.也能够说,我们已经入门了,能够蹒跚的走路了. 本篇将解说cocos2dx中非常重要的touch回调机制.你肯定记得第一章做定时器 ...

  3. ARM LDR伪指令使用方法具体解释

    LDR伪指令 10.45 LDR pseudo-instruction   功能:把一个32位马上数或一个32位的内存地址载入到一个寄存器中. 注意:这里描写叙述的是LDR伪指令,而不是LDR指令   ...

  4. 第一个MyBatis程序

    最近研究了一些MyBatis技术,虽然工作中还未用到,但是觉得了解一下也是不错的.这里记录了第一个简单的Demo程序,防止自己忘记. 第一步需要配置Mybatis-config.xml文件.注意:这里 ...

  5. C#中如何只保留小数点后面两位?

    string.format("%.4f",1/3) 1.Math.Round(0.333333,2);//按照四舍五入的国际标准2. double dbdata=0.335333; ...

  6. CSS3属性transform详解之(旋转:rotate,缩放:scale,倾斜:skew,移动:translate)(转载)

    在CSS3中,可以利用transform功能来实现文字或图像的旋转.缩放.倾斜.移动这四种类型的变形处理,本文将对此做详细介绍. 一.旋转 rotate 用法:transform: rotate(45 ...

  7. Andrord问题小结

    问题描述:Gradle version 2.10 is required. Current version is 2.8.Gradle版本由2.8升为2.10后,发现所有依赖play-services ...

  8. 使用API查询天气

    服务端代码 [HttpPost] public ActionResult GetWeather() { HttpWebRequest request = (HttpWebRequest)HttpWeb ...

  9. JS时间戳与日期类型格式相互转换

    function datetime_to_unix(datetime){     var tmp_datetime = datetime.replace(/:/g,'-');     tmp_date ...

  10. Struts2中使用Session的两种方法

    在Struts2里,如果需要在Action中使用到session,可以使用下面两种方式: 通过ActionContext 类中的方法getSession得到 Action实现org.apache.st ...