-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVa469.py
68 lines (55 loc) · 2.16 KB
/
UVa469.py
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
def measure_water(row, col):
global land_matrix
global explored_matrix
global row_len
global col_len
#Let's check if checking the top row doesn't exceed our bounds
no_more_adjacent = True
explored_matrix[row][col] = 'Y'
answer = 1
if(row - 1 >= 0): #N
if(land_matrix[row-1][col] == 'W' and explored_matrix[row-1][col] == 'N'):
answer += measure_water(row-1, col)
if(row - 1 >= 0 and col - 1 >= 0): #NW
if(land_matrix[row-1][col-1] == 'W' and explored_matrix[row-1][col-1] == 'N'):
answer += measure_water(row-1, col-1)
if(row - 1 >= 0 and col + 1 < col_len): #NE
if(land_matrix[row-1][col+1] == 'W' and explored_matrix[row-1][col+1] == 'N'):
answer += measure_water(row-1, col+1)
if(col - 1 >= 0): #W
if(land_matrix[row][col-1] == 'W' and explored_matrix[row][col-1] == 'N'):
answer += measure_water(row, col-1)
if(col + 1 < col_len): #E
if(land_matrix[row][col+1] == 'W' and explored_matrix[row][col+1] == 'N'):
print("East")
print(row, col)
answer += measure_water(row, col+1)
if(row + 1 < row_len and col - 1 >= 0): #SW
if(land_matrix[row+1][col-1] == 'W' and explored_matrix[row+1][col-1] == 'N'):
answer += measure_water(row+1, col-1)
if(row + 1 < row_len): #S
if(land_matrix[row+1][col] == 'W' and explored_matrix[row+1][col] == 'N'):
answer += measure_water(row+1, col)
if(row + 1 < row_len and col + 1 < col_len): #SE
if(land_matrix[row+1][col+1] == 'W' and explored_matrix[row+1][col+1] == 'N'):
print("SouthEast")
print(row, col)
answer += measure_water(row+1, col+1)
return answer
if __name__ == "__main__":
land_matrix = [ "LLLLLLLLL",
"LLWWLLWLL",
"LWWLLLLLL",
"LWWWLWWLL",
"LLLWWWLLL",
"LLLLLLLLL",
"LLLWWLLWL",
"LLWLWLLLL",
"LLLLLLLLL" ]
row_len = len(land_matrix[0])
col_len = len(land_matrix)
explored_matrix = [['N' for i in range(len(land_matrix[0]))] for j in range(len(land_matrix))]
print(measure_water(2, 1))
print(measure_water(6, 4))
# print(land_matrix)
# print(explored_matrix)