Ver código fonte

Qual-a: final solution

Gildas Chabot 8 anos atrás
pai
commit
39e5c21afe
1 arquivos alterados com 26 adições e 2 exclusões
  1. 26 2
      2017.0-QualificationRound/a.ProgressBar.py

+ 26 - 2
2017.0-QualificationRound/a.ProgressBar.py

@@ -1,8 +1,32 @@
1
+import numpy as np
2
+
3
+# From: http://stackoverflow.com/a/35178910
4
+def angle(x, y):
5
+    a = np.array([50, 100, 0])
6
+    b = np.array([50, 50, 0])
7
+    c = np.array([x, y, 0])
8
+
9
+    ba = a - b
10
+    bc = c - b
11
+
12
+    cosine_angle = np.dot(ba, bc) / (np.linalg.norm(ba) * np.linalg.norm(bc))
13
+    angle = np.arccos(cosine_angle)
14
+
15
+    return np.degrees(angle)
1 16
 
2 17
 def solve(S):
3 18
     p, x, y = S
4
-    print("p={0}, x={1}, y={2}".format(p, x, y))
5
-    return 'black'
19
+    #print("p={0}, x={1}, y={2}".format(p, x, y))
20
+    dist=np.sqrt((x-50)*(x-50)+(y-50)*(y-50))
21
+    if dist > 50:
22
+        return 'white'
23
+    a=angle(x,y)
24
+    if x < 50:
25
+        a=360-a
26
+    #print('Angle={0}'.format(a))
27
+    if p >= 100*a/360:
28
+        return 'black'
29
+    return 'white'
6 30
 
7 31
 if __name__ == "__main__":
8 32
     import fileinput