t | import math | t | import math |
| | | |
| def cross_product(o, a, b): | | def cross_product(o, a, b): |
| return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) | | return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) |
| | | |
| def is_convex_polygon(points): | | def is_convex_polygon(points): |
| if len(points) < 3: | | if len(points) < 3: |
| return False | | return False |
| start = min(points, key=lambda p: (p[1], p[0])) | | start = min(points, key=lambda p: (p[1], p[0])) |
| points.remove(start) | | points.remove(start) |
| points.sort(key=lambda p: (math.atan2(p[1] - start[1], p[0] - start[ | | points.sort(key=lambda p: (math.atan2(p[1] - start[1], p[0] - start[ |
| 0]), p[0], p[1])) | | 0]), p[0], p[1])) |
| points.insert(0, start) | | points.insert(0, start) |
| hull = [points[0], points[1]] | | hull = [points[0], points[1]] |
| for i in range(2, len(points)): | | for i in range(2, len(points)): |
| while len(hull) > 1 and cross_product(hull[-2], hull[-1], points | | while len(hull) > 1 and cross_product(hull[-2], hull[-1], points |
| [i]) <= 0: | | [i]) <= 0: |
| hull.pop() | | hull.pop() |
| hull.append(points[i]) | | hull.append(points[i]) |
| if len(hull) == len(points): | | if len(hull) == len(points): |
| return True | | return True |
| return False | | return False |
| | | |
| def main(): | | def main(): |
| points = [] | | points = [] |
| while True: | | while True: |
| line = input().strip() | | line = input().strip() |
| if not line: | | if not line: |
| break | | break |
| x, y = map(int, line.split(',')) | | x, y = map(int, line.split(',')) |
| points.append((x, y)) | | points.append((x, y)) |
| if is_convex_polygon(points): | | if is_convex_polygon(points): |
| print(True) | | print(True) |
| else: | | else: |
| print(False) | | print(False) |
| main() | | main() |