-
Notifications
You must be signed in to change notification settings - Fork 1
/
Laughing_Bomb.c
102 lines (80 loc) · 1.9 KB
/
Laughing_Bomb.c
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <stdio.h>
#define MAX_SIZE 101
int citymap[MAX_SIZE][MAX_SIZE];
int visited[MAX_SIZE][MAX_SIZE];
int Answer;
int row_size = 0;
int col_size = 0;
int bomb_row, bomb_col;
void traverse(int row, int col, int cur_value)
{
if ((row < 1) || (row > row_size) || (col < 1) || (col > col_size))
return;
if (citymap[row][col] == 0)
return;
if (visited[row][col])
{
if(citymap[row][col] > cur_value)
{
citymap[row][col] = cur_value;
}
else
{
return;
}
}
else
{
visited[row][col] = 1;
citymap[row][col] = cur_value;
}
traverse(row, col+1, cur_value + 1);
traverse(row+1, col, cur_value + 1);
traverse(row, col-1, cur_value + 1);
traverse(row-1, col, cur_value + 1);
return;
}
int main(void)
{
int tc, T;
int i, j;
scanf("%d", &T);
for (tc = 0; tc < T; tc++)
{
row_size = 0;
col_size = 0;
bomb_row = 0;
bomb_col = 0;
for (i = 0; i < MAX_SIZE; i++)
{
for (j = 0; j < MAX_SIZE; j++)
{
citymap[i][j] = 0;
visited[i][j] = 0;
}
}
Answer = 0;
scanf("%d", &col_size);
scanf("%d", &row_size);
for (i = 1; i <= row_size; i++)
{
for (j = 1; j <= col_size; j++)
{
scanf("%d", &citymap[i][j]);
}
}
scanf("%d %d", &bomb_col, &bomb_row);
citymap[bomb_row][bomb_col] = 1;
traverse(bomb_row, bomb_col,1);
for (i = 1; i <= row_size; i++)
{
for (j = 1; j <= col_size; j++)
{
if (Answer < citymap[i][j])
Answer = citymap[i][j];
}
}
printf("%d \n", Answer);
}
return 0;
}