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

    Avoid The Lakes

     

    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 exactly K (1 ≤ KN × 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: N, M, 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<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 
     6 int map[105][105];
     7 int m,n,cnt;
     8 int d[4][2]={1,0,0,1,-1,0,0,-1};
     9 
    10 void dfs(int x,int y)
    11 {
    12     if(x<=0||x>m||y<=0||y>n||map[x][y]==0)
    13     return;
    14     map[x][y]=0;
    15     cnt++;
    16     for(int i=0;i<4;i++)
    17     {
    18         int xx=x+d[i][0];
    19         int yy=y+d[i][1];
    20         dfs(xx,yy);
    21     }
    22     
    23 }
    24 
    25 int main()
    26 {
    27     int i,j,x,y,k,ans;
    28     while(scanf("%d%d%d",&m,&n,&k)!=EOF)
    29     {
    30         ans=0;
    31         memset(map,0,sizeof(map));
    32         for(i=0;i<k;i++)
    33         {
    34             scanf("%d%d",&x,&y);
    35             map[x][y]=1;
    36         }
    37         for(i=1;i<=m;i++)
    38         for(j=1;j<=n;j++)
    39         {
    40             if(map[i][j]==1)
    41             {
    42                 cnt=0;
    43                 dfs(i,j);
    44                 ans=max(cnt,ans);
    45             }
    46         }
    47         printf("%d
    ",ans);
    48     }
    49     return 0;
    50 }
  • 相关阅读:
    Linux yum命令重装mysql
    Java多线程编程<一>
    Java内存区域与内存溢出异常
    实现一个线程安全的Queue队列
    Java 原始数据类型转换
    对象-关系映射ORM(Object Relational Mapping)(转)
    2进制,16进制,BCD,ascii,序列化对象相互转换
    Apache MINA 框架之默认session管理类实现
    Struts.properties(转)
    vue常用插件-数字滚动效果vue-count-to
  • 原文地址:https://www.cnblogs.com/homura/p/4703519.html
Copyright © 2011-2022 走看看