-
Notifications
You must be signed in to change notification settings - Fork 0
/
gerrymandering.py
28 lines (28 loc) · 986 Bytes
/
gerrymandering.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
import sys; input = sys.stdin.readline
from math import floor
precints, districts = list(map(int, input().split()))
scores = {}
for _ in range(precints):
d, a, b = list(map(int, input().split()))
if d not in scores: scores[d] = [a, b]
else:
scores[d][0] += a
scores[d][1] += b
total = [0, 0]
V = 0
for i in range(1, districts + 1):
if scores[i][0] > scores[i][1]:
sys.stdout.write("A ")
sys.stdout.write(f"{scores[i][0] - floor(sum(scores[i]) / 2) - 1} ")
sys.stdout.write(f"{scores[i][1]}")
total[0] += scores[i][0] - floor(sum(scores[i]) / 2) - 1
total[1] += scores[i][1]
else:
sys.stdout.write("B ")
sys.stdout.write(f"{scores[i][0]} ")
sys.stdout.write(f"{scores[i][1] - floor(sum(scores[i]) / 2) - 1}")
total[0] += scores[i][0]
total[1] += scores[i][1] - floor(sum(scores[i]) / 2) - 1
V += sum(scores[i])
print()
print(f"{abs(total[0] - total[1]) / V}")