Avoid The Lakes

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Submit Status

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 ≤ 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<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 int a[111][111];
 7 int dx[4]={-1,1,0,0};
 8 int dy[4]={0,0,-1,1};
 9 int n,m,k,ans;
10 void dfs(int x,int y)
11 {
12     if(a[x][y]&&x>=1&&y>=1&&x<=n&&y<=m)
13     {
14         ans++;
15         a[x][y]=0;
16         for(int i = 0;i < 4;i++)
17         {
18             int nx=x+dx[i];
19             int ny=y+dy[i];
20             dfs(nx,ny);
21         }
22     }
23 }
24 int main()
25 {
26     while(scanf("%d%d%d",&n,&m,&k)!=EOF)
27     {
28         int i,j,max=0;
29         memset(a,0,sizeof(a));
30         for(i = 0;i < k;i++)
31         {
32             int r,c;
33             scanf("%d %d",&r,&c);
34             a[r][c]=1;
35         }
36         for(i = 1;i <= n;i++)  //从1开始,别从0.小地方WA了N次
37             for(j = 1;j <= m ;j++)
38             {
39                 ans = 0;
40                 dfs(i,j);
41                 if(ans>max)
42                 max=ans;
43             }
44             printf("%d\n",max);
45     }
46     return 0;
47 }
时间: 2024-10-15 07:15:58

Avoid The Lakes的相关文章

[深度优先搜索] POJ 3620 Avoid The Lakes

Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8173   Accepted: 4270 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 wate

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 si

Avoid The Lakes POJ

Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6409   Accepted: 3466 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 wate

POJ 3620 Avoid The Lakes (求连接最长的线)(DFS)

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 larges

POJ 3620 Avoid The Lakes(DFS)

题目链接:http://poj.org/problem?id=3620 DFS基础题~ #include<cstdio> #include<iostream> #include<sstream> #include<cstdlib> #include<cstring> #include<string> #include<climits> #include<cmath> #include<algorithm&

Poj3620--Avoid The Lakes(基础Dfs)

Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6908   Accepted: 3680 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 wate

Avoid The Lakes--poj3620

Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7023   Accepted: 3735 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 wate

POJ 3620--Avoid The Lakes【DFS】

Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6775   Accepted: 3620 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 wate

poj练习题的方法

poj1010--邮票问题 DFSpoj1011--Sticks dfs + 剪枝poj1020--拼蛋糕poj1054--The Troublesome Frogpoj1062--昂贵的聘礼poj1077--Eightpoj1084--Square Destroyerpoj1085--Triangle War(博弈,極大極小搜索+alpha_beta剪枝)poj1088--滑雪poj1129--Channel Allocation 着色问题 dfspoj1154--letters (dfs)p