POJ 3620 Avoid The Lakes (for the longest connecting line) (DFS)

Source: Internet
Author: User

Description

Farmer John's farm was flooded in the most recent storm, a fact-only aggravated by the information so his cows is death Ly afraid of water. His insurance agency would only repay him, however, a 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 ≤ ) columns. Each cell in the grid is either dry or submerged, and exactly K (1≤ kN x M) of the Cells are submerged. As one would expect, a lake has a central cell to which and other cells connect by sharing a long edge (not a corner). Any cell this shares a long edge with the central cell or shares a long edge with any connected cell becomes a connected C Ell 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 II space separated integers that is its row and co Lumn: R and C

Output

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

Sample Input
3 4 53 22 23 12 31 1
Sample Output
4
Give a string of coordinates, one for each of them, and calculate the maximum number of coordinates that each consists of.
1#include <cstdio>2#include <string.h>3 intdx[4]={-1,1,0,0};4 intdy[4]={0,0,-1,1};5 intn,m,map[ Max][ Max],x,y,i,max,ans,k,j;6 voidFintXinty)7 {8     intI,nx,ny;9      for(i =0; I <4; i++)Ten     { Onenx=x+Dx[i]; Any=y+Dy[i]; -         if(NX >0&& NY >0&& NX <= N && ny <=m && map[nx][ny] = =1) -         { theans++; -map[nx][ny]=0; - f (nx,ny); -         } +     } - } + intMain () A { at      while(SCANF (" %d%d%d", &n,&m,&k)! =EOF) -     { -max=0; -memset (Map,0,sizeof(map)); -          for(i =0; I < K; i++) -         { inscanf"%d%d",&x,&y); -map[x][y]=1;//1 means not passing . to         } +          for(i =1; I <=n; i++) -         { the              for(j =1; J <= M; J + +) *             { $                 Panax Notoginseng                 if(Map[i][j] = =1) -                 {     theans=1; +map[i][j]=0; A f (i,j); theMax=max>ans?Max:ans; +                 } -                  $             } $              -         } -printf"%d\n", max); the     } -}

POJ 3620 Avoid The Lakes (for the longest connecting line) (DFS)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.