Kattis - Maximum Number of Colinear Points
Author: Benjamin Qi
Explanation
Add one to the line passing through each pair of points.
Implementation
Time Complexity:
C++
#include <bits/stdc++.h>using namespace std;pair<pair<int, int>, int> get_line(pair<int, int> a, pair<int, int> b) {pair<int, int> z = {b.first - a.first, b.second - a.second};swap(z.first, z.second);z.first *= -1;int g = __gcd(z.first, z.second);z.first /= g;
Python
import mathfrom collections import defaultdictfrom typing import Tupledef get_line(a: Tuple[int, int], b: Tuple[int, int]) -> Tuple[Tuple[int, int], int]:z = (b[0] - a[0], b[1] - a[1])z = (-z[1], z[0])g = math.gcd(z[0], z[1])
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!