水题
1 #include <iostream>
2 #include <stdio.h>
3 #include <string.h>
4 using namespace std;
5
6 const int maxx=100;
7
8 int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
9 int n,m;
10 bool wet[maxx+2][maxx+2],visit[maxx+2][maxx+2];
11 int ans,cnt;
12 struct A
13 {
14 int x,y;
15 };
16 A point[maxx*maxx+10];
17 bool judege(int a,int b)
18 {
19 if(a>=1 && a<=n && b>=1 &&b<=m )return 1;
20 return 0;
21 }
22 void dfsvisit(int x,int y)
23 {
24 for(int i=0;i<4;i++)
25 {
26 int a=x+dir[i][0];
27 int b=y+dir[i][1];
28 if(judege(a,b)&&wet[a][b] && !visit[a][b])
29 {
30 visit[a][b]=1;
31 cnt++;
32 dfsvisit(a,b);
33 }
34 }
35 }
36 void dfs(int k)
37 {
38 for(int i=1;i<=k;i++)
39 {
40 if(wet[point[i].x][point[i].y] && !visit[point[i].x][point[i].y])
41 {
42 visit[point[i].x][point[i].y]=1;
43 cnt=1;
44 dfsvisit(point[i].x,point[i].y);
45 if(ans<cnt)
46 ans=cnt;
47 }
48 }
49 }
50 int main()
51 {
52 int k,x,y,i;
53 freopen("in.txt","r",stdin);
54 while(scanf("%d%d%d",&n,&m,&k)!=EOF)
55 {
56 ans=0;
57 memset(wet,0,sizeof(wet));
58 memset(visit,0,sizeof(visit));
59 for(i=1;i<=k;i++)
60 {
61 scanf("%d%d",&point[i].x,&point[i].y);
62 wet[point[i].x][point[i].y]=1;
63 }
64 dfs(k);
65 printf("%d\n",ans);
66 }
67 return 0;
68 }