-
Notifications
You must be signed in to change notification settings - Fork 0
/
102.py
68 lines (57 loc) · 2.05 KB
/
102.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# # # # # # #
# Author phantomhive #
# 31-07-2019 #
# # # # # # #
from collections import Counter, deque, defaultdict
from math import ceil, floor, sqrt, log, factorial
from fractions import Fraction, gcd
from sys import stdin, stdout
from bisect import bisect, bisect_left, bisect_right
from heapq import heapify, heappop, heappush, heappushpop
from time import time
def lcm(a,b): return (a*b) / gcd(a,b)
cin, cout = stdin.readline, stdout.write
# Start time
START = time()
class coordinate:
def __init__(self, x, y):
self.x = x
self.y = y
ORIGIN = coordinate(0, 0)
class triangle:
def __init__(self, points):
self.a = coordinate(points[0], points[1])
self.b = coordinate(points[2], points[3])
self.c = coordinate(points[4], points[5])
def to_points(self, a, b, c):
return [a.x, a.y, b.x, b.y, c.x, c.y]
def area(self):
area_2 = sum([
(self.a).x * ((self.b).y-(self.c).y),
(self.b).x * ((self.c).y-(self.a).y),
(self.c).x * ((self.a).y-(self.b).y),
])
area = area_2/2.0
return abs(area)
def check_origin_inside(self):
triangle1 = triangle(self.to_points(self.a, self.b, ORIGIN))
triangle2 = triangle(self.to_points(self.b, self.c, ORIGIN))
triangle3 = triangle(self.to_points(self.a, self.c, ORIGIN))
return (triangle1.area() + triangle2.area() + triangle3.area()) == self.area()
def __str__(self):
return (
str(self.a.x) + ' ' + str(self.a.y) + '; '+
str(self.b.x) + ' ' + str(self.b.y) + '; '+
str(self.c.x) + ' ' + str(self.c.y) + ';'
)
with open('input102.txt', 'r') as my_file:
triangles = [ triangle(map(int, t_point.split(','))) for t_point in my_file]
count = 0
for triangle_ob in triangles:
if triangle_ob.check_origin_inside():
count+=1
cout('Total triangles : %d\n'%count)
# End Time
END = time()
seconds = END - START
print("Total time %d minutes %d seconds"%(seconds/60, seconds%60))