YS - Sort Points by Argument
Author: Jeffrey Zhang
Solution
The idea for this problem is fairly straightforward. Let us define the "argument" of a point as the angle it forms with the origin. Given points , we can find the argument of the point by calling . To sort the points in the counterclockwise order, we just sort the points based on their argument from smallest to largest.
The problem conviently required us to have the sorted points start from the 3rd quadrant and end at the 2nd quadrant, which matches with the characteristics of the builtin function, where the 3rd and 4th quadrant points have negative angle values and 1st and 2nd quadrant points have positive angle values.
Implementation
Time Complexity: , where is the computation complexity for
C++
#include <bits/stdc++.h>using namespace std;typedef long long ll;struct Point {ll x;ll y;};int main() {
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!