Browse Source

Round 1 - Fighting the zombies - partial

Gildas Chabot 8 years ago
parent
commit
62f463f071

+ 44 - 0
2017.1-RoundOne/b.FightingZombies.py

@@ -0,0 +1,44 @@
1
+import numpy as np
2
+
3
+class Plate:
4
+    def __init__(self, h, s, z):
5
+        self.height = []
6
+        self.space = s
7
+        self.zombies = z
8
+
9
+def addToPlates(plates, R, i, x, y):
10
+    print(plates)
11
+    newSpace = [x-R/2, x+R/2, y+R/2, y-R/2]
12
+    newPlate = Plate(1, newSpace, [i])
13
+    toAdd = []
14
+    for p in plates:
15
+        if newSpace[0] <= p.space[1] and newSpace[1] >= p.space[0] and newSpace[2] > p.space[3] and newSpace[3] < p.space[2]:
16
+            # Overlap
17
+            overlapSpace = [max(newSpace[0], p.space[0]), min(newSpace[1], p.space[1]), min(newSpace[2], p.space[2]), max(newSpace[3], p.space[3])]
18
+            print(p.zombies)
19
+            overlapPlate = Plate(newPlate.height + p.height, overlapSpace, p.zombies.extend(newPlate.zombies))
20
+            toAdd.append(overlapPlate)
21
+    plates.append(newPlate)
22
+    plates.extend(toAdd)
23
+
24
+def solve(N, R, XY):
25
+    # print("N={0}, R={1}, XY={2}".format(N, R, XY))
26
+
27
+    # Create plates
28
+    plates = []
29
+    for i, xy in enumerate(XY):
30
+        x, y = xy
31
+        addToPlates(plates, R, i, x, y)
32
+    print(plates)
33
+    return 'white'
34
+
35
+if __name__ == "__main__":
36
+    import fileinput
37
+    f = fileinput.input()
38
+
39
+    T = int(f.readline())
40
+    for case in range(1, T+1):
41
+        N, R = [int(i) for i in f.readline().split()]
42
+        XY = [[int(i) for i in f.readline().split()] for x in range(N)]
43
+        solution = solve(N, R, XY)
44
+        print("Case #{0}: {1}".format(case, solution))

+ 35 - 0
2017.1-RoundOne/fighting_the_zombies_example_input.txt

@@ -0,0 +1,35 @@
1
+5
2
+7 3
3
+1 5
4
+2 3
5
+2 1
6
+5 1
7
+6 3
8
+4 4
9
+4 5
10
+4 1
11
+0 0
12
+0 2
13
+10 0
14
+10 2
15
+4 2
16
+0 0
17
+0 2
18
+10 0
19
+10 2
20
+7 3
21
+8 5
22
+3 6
23
+9 2
24
+4 5
25
+3 2
26
+1 8
27
+2 8
28
+7 6
29
+8 5
30
+3 6
31
+9 2
32
+4 5
33
+3 2
34
+1 8
35
+2 8