forked from KenMercusLai/checkio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Buildings visibility.py
40 lines (39 loc) · 1.15 KB
/
Buildings visibility.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
def checkio(buildings):
view_map = [[-1 for x in range(max([i[2] for i in buildings]) + 1)]
for x in range(max([i[4] for i in buildings]) + 1)]
buildings = sorted(buildings, key=lambda x: x[3], reverse=True)
for i, j in enumerate(buildings):
for k in range(int(j[4])):
view_map[k][j[0]:j[2]] = [i] * (j[2] - j[0])
return len(set([j for i in view_map for j in i if j != -1]))
if __name__ == '__main__':
assert checkio([
[1, 1, 4, 5, 3.5],
[2, 6, 4, 8, 5],
[5, 1, 9, 3, 6],
[5, 5, 6, 6, 8],
[7, 4, 10, 6, 4],
[5, 7, 10, 8, 3]
]) == 5, "First"
assert checkio([
[1, 1, 11, 2, 2],
[2, 3, 10, 4, 1],
[3, 5, 9, 6, 3],
[4, 7, 8, 8, 2]
]) == 2, "Second"
assert checkio([
[1, 1, 3, 3, 6],
[5, 1, 7, 3, 6],
[9, 1, 11, 3, 6],
[1, 4, 3, 6, 6],
[5, 4, 7, 6, 6],
[9, 4, 11, 6, 6],
[1, 7, 11, 8, 3.25]
]) == 4, "Third"
assert checkio([
[0, 0, 1, 1, 10]
]) == 1, "Alone"
assert checkio([
[2, 2, 3, 3, 4],
[2, 5, 3, 6, 4]
]) == 1, "Shadow"