618C - Constellation - CodeForces Solution


geometry implementation *1600

Please click on ads to support us..

Python Code:

import sys
from functools import cmp_to_key

input = sys.stdin.read
INF = float('inf')

class Point:
    def __init__(self, x=0, y=0, id=0):
        self.x = x
        self.y = y
        self.id = id

    def __lt__(self, other):
        if self.x != other.x:
            return self.x < other.x
        return self.y < other.y

def check(p1, p2, p3):
    x1, y1 = p1.x, p1.y
    x2, y2 = p2.x, p2.y
    x3, y3 = p3.x, p3.y

    if (x1 == x2 and x1 == x3) or (y1 == y2 and y1 == y3):
        return False
    return (y1 - y2) * (x1 - x3) != (y1 - y3) * (x1 - x2)

def solve():
    input_data = input().split()
    n = int(input_data[0])
    points = []
    index = 1
    for i in range(1, n + 1):
        x = int(input_data[index])
        y = int(input_data[index + 1])
        points.append(Point(x, y, i))
        index += 2
    
    points.sort()

    for i in range(n - 2):
        if check(points[i], points[i + 1], points[i + 2]):
            print(points[i].id, points[i + 1].id, points[i + 2].id)
            return

def main():
    solve()

if __name__ == "__main__":
    main()


Comments

Submit
0 Comments
More Questions

1712D - Empty Graph
1712B - Woeful Permutation
1712C - Sort Zero
1028B - Unnatural Conditions
735B - Urbanization
746C - Tram
1278B - A and B
1353D - Constructing the Array
1269C - Long Beautiful Integer
1076A - Minimizing the String
913C - Party Lemonade
1313A - Fast Food Restaurant
681A - A Good Contest
1585F - Non-equal Neighbours
747A - Display Size
285A - Slightly Decreasing Permutations
515C - Drazil and Factorial
1151E - Number of Components
1151F - Sonya and Informatics
556A - Case of the Zeros and Ones
867A - Between the Offices
1569A - Balanced Substring
260A - Adding Digits
1698C - 3SUM Closure
1029B - Creating the Contest
1421A - XORwice
1029A - Many Equal Substrings
1675D - Vertical Paths
1271C - Shawarma Tent
805A - Fake NP