-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path871.cpp
More file actions
48 lines (47 loc) · 1.03 KB
/
871.cpp
File metadata and controls
48 lines (47 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
char a[50][50];
int N, M;
int call(int i, int j) {
int sum = 0;
if (i < 0 || j < 0 || i >= N || j >= M) return 0;
if (a[i][j] == '0') return 0;
sum = 1;
a[i][j] = '0';
for (int k = 0; k < 8; k++) {
sum += call(i + dx[k], j + dy[k]);
}
return sum;
}
int main() {
int n, m, i, j, k, tc, t = 1;
cin >> tc;
getchar();
getchar();
while (tc--) {
N = n;
M = m;
i = 0;
while (gets(a[i])) {
if (strlen(a[i]) == 0) break;
i++;
}
N = i;
M = strlen(a[0]);
int mx = 0;
for (i = 0; i < N; i++) {
for (j = 0; j < M; j++) {
if (a[i][j] == '1') {
k = call(i, j);
if (k > mx) mx = k;
}
}
}
if (t != 1) puts("");
t++;
printf("%d\n", mx);
}
return 0;
}