Links: https://ac.nowcoder.com/acm/contest/910/D
Source: Cattle-off network
Farmer John's farm was flooded in the recent storm, the fact that news of his cows because of extreme fear of water deteriorates.
However, his insurance company will only be based on the maximum size of his farm "lake" to pay him a sum of money.
Farm represented as a rectangular grid, there are N (1≤N≤100) rows and M (1≤M≤100) column. Each lattice grid is either dry,
Either submerged, but exactly K (1≤K≤N × M) lattice are submerged. As one might expect, a "lake" have a
Central grid, the grid connected thereto other by sharing one edge (only four directions, not diagonal meaning). Any shared with the central grid of one side or the central grid
Source: Cattle-off network
Enter a description:
The first line contains three integers N, M, K, respectively, the rectangular grid of N rows, M columns, K a submerged grid.
Next K rows, each row has two integers R, C. It represents submerged in a lattice row R, column C.
Output Description:
The number of output lattice largest "lake" contained
Entry
3 4 5 3 2 2 2 3 1 2 3 1 1
Export
4
qwq this question is very simple matter to calculate the size of each piece of the Lake District, the largest district and then on the line
#include <stdio.h> #include <the iostream> #include <stdlib.h> #include <algorithm> the using namespace STD; const int MAXN 1E2 + = 2 ; BOOL VIS [MAXN] [MAXN]; // matrix containing said lattice whether flooded, true is flooded int SUM = 0 ; int ANS = 0 ; void DFS ( int X, int Y) // to vis [x] [y] to find the center of the sheet size of the engulfing zone { iF ( VIS [X] [Y]) // find the lattice not being labeled { VIS [X] [Y] =to false ; // to even the place marker at SUM ++ ; DFS (X + . 1 , Y); DFS (X - . 1 , Y); DFS (X, Y + . 1 ); DFS (X, Y - . 1 ); } return ; } int main () { int n-, K, m; CIN >> >> m >> n- K; // initializes the matrix for ( int I = . 1 ; I <= n-; I ++ ) for ( int= J . 1 ; J <m; J ++ ) VIS [I] [J] = to false ; the while (K-- ) { int X, Y; CIN >> >> X Y; VIS [X] [Y] = to true ; } for ( int I = . 1 ; I <= n-; I ++ ) for ( int J = . 1 ; J <m; J ++ ) { SUM = 0 ; // the DFS each point can actually optimize a little bit, but FIG small I did not have to do DFS (I, J); ANS = max (SUM, ANS); // get the maximum area } COUT << ANS << endl; System ( " the Pause " ); return 0 ; }