zoukankan      html  css  js  c++  java
  • Avoid The Lakes

    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
     题解:相当于水池数目那题,只不过这个是找最大的水的个数;
    代码:
     1 #include<stdio.h>
     2 #include<string.h>
     3 int N,M,max,step;
     4 int map[110][110];
     5 void dfs(int x,int y){
     6     if(!map[x][y]||x<0||x>=N||y<0||y>=M)return;
     7     map[x][y]=0;step++;
     8     if(step>max)max=step;
     9     dfs(x+1,y);dfs(x-1,y);dfs(x,y+1),dfs(x,y-1);
    10 //    step--;map[x][y]=1;
    11     return;
    12 }
    13 int main(){
    14     int K,x,y;
    15     while(~scanf("%d%d%d",&N,&M,&K)){
    16         memset(map,0,sizeof(map));
    17         while(K--){
    18             scanf("%d%d",&x,&y);
    19             map[x-1][y-1]=1;
    20         }
    21         max=step=0;
    22         for(x=0;x<N;x++){
    23             for(y=0;y<M;y++){//printf("%d ",map[x][y]);
    24                 if(map[x][y])step=0,dfs(x,y);
    25             }//puts("");
    26         }
    27         printf("%d
    ",max);
    28     }
    29     return 0;
    30 }
  • 相关阅读:
    APP专项测试方法有哪些?
    软件测试基础知识
    软件测试入门随笔——软件测试基础知识
    如何做接口测试
    App测试页面滑动
    什么是接口测试
    自动化测试
    测试用例设计方法
    Monkey测试手机BUG重现及解决方法
    软件测试工程师需要具备哪些数据库知识
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4703397.html
Copyright © 2011-2022 走看看