-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddlepoint.py
49 lines (42 loc) · 1.29 KB
/
middlepoint.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
from collections import defaultdict
class Test:
def __init__(self, num_points = 0):
self.xeye = []
self.xeyo = []
self.xoye = []
self.xoyo = []
self.num_points = num_points
self.winners = 0
def addPoint(self, pair):
x = pair[0]
y = pair[1]
if x % 2 == 0:
if y % 2 == 0:
self.xeye.append((x,y))
else:
self.xeyo.append((x,y))
else:
if y % 2 == 0:
self.xoye.append((x,y))
else:
self.xoyo.append((x,y))
def calculateWinners(self):
x1 = len(self.xeye)
x2 = len(self.xeyo)
x3 = len(self.xoye)
x4 = len(self.xoyo)
self.winners += (x1 * (x1 - 1)) / 2
self.winners += (x2 * (x2 - 1)) / 2
self.winners += (x3 * (x3 - 1)) / 2
self.winners += (x4 * (x4 - 1)) / 2
print self.winners
if __name__ == "__main__":
num_tests = int(raw_input())
while num_tests > 0:
num_tuples = int(raw_input())
currentTest = Test(num_tuples)
while num_tuples > 0:
currentTest.addPoint(tuple(map(int, raw_input().split(' '))))
num_tuples -= 1
currentTest.calculateWinners()
num_tests -= 1