compro-library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub ningenMe/compro-library

:heavy_check_mark: test/geometory/Argument-sort-by-atan2l.test.cpp

Depends on

Code

#define PROBLEM "https://judge.yosupo.jp/problem/sort_points_by_argument"

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;
#include "../../lib/70-geometory/Argument.cpp"

int main(void){
    int N; cin >> N;
    vector<pair<long long,long long>> points(N);
    for(int i = 0; i < N; ++i) {
        long long a,b; cin >> a >> b;
        points[i] = {a,b};
    }
    auto idx = Argument::sort_by_atan2l<long long>(points);
    for(int i = 0; i < N; ++i) {
        cout << points[idx[i]].first << " " << points[idx[i]].second << endl; 
    }
	return 0;
}
#line 1 "test/geometory/Argument-sort-by-atan2l.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/sort_points_by_argument"

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;
#line 1 "lib/70-geometory/Argument.cpp"
/*
 * @title Argument - 偏角
 * @docs md/geometory/Argument.md
 */
class Argument {
public:
    template<class T> inline static vector<int> sort_by_atan2l(vector<pair<T,T>> points){
        int N = points.size();
        vector<long double> arg(N);
        for(int i = 0; i < N; ++i) arg[i] = atan2l(points[i].second,points[i].first);
        vector<int> res(N);
        iota(res.begin(),res.end(),0);
        sort(res.begin(),res.end(),[&](int l,int r){return arg[l] < arg[r];});
        return res;
    }
};
#line 11 "test/geometory/Argument-sort-by-atan2l.test.cpp"

int main(void){
    int N; cin >> N;
    vector<pair<long long,long long>> points(N);
    for(int i = 0; i < N; ++i) {
        long long a,b; cin >> a >> b;
        points[i] = {a,b};
    }
    auto idx = Argument::sort_by_atan2l<long long>(points);
    for(int i = 0; i < N; ++i) {
        cout << points[idx[i]].first << " " << points[idx[i]].second << endl; 
    }
	return 0;
}
Back to top page