ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1207. Median on the Plane

Posted by farid 21 Aug 2019 16:49
#include <bits/stdc++.h>
using namespace std;

int const N = 123456;
#define pi acos(-1.0)
typedef long long ll;

int ar[N],xar[N],uses[N];

struct points {
double x, y;
int id;
points() {}
points(double x, double y) : x(x), y(y) {}
} ;

double ang(const points &p){
double res = atan2(p.y, p.x);
if(res < 0) res += 2.0 * pi;
return res;
}

struct cmp{
inline bool operator () (const points &p1, const points &p2){
double ang1 = ang(p1)*(180/pi), ang2 = ang(p2)*(180/pi);
if(fabs(ang1 - ang2) < 1e-9){
ll d1 = (ll)p1.x * (ll)p1.x + (ll)p1.y * (ll)p1.y;
ll d2 = (ll)p2.x * (ll)p2.x + (ll)p2.y * (ll)p2.y;

return d1 < d2;
}
return ang1 < ang2;
}
};

points pt[N];

int main() {
int n;
cin >> n;
for(int i = 0; i < n; i++){
cin >> pt[i].x >> pt[i].y;
pt[i].id = i+1;
}
sort(pt, pt+n, cmp());
cout<<pt[0].id<<" "<<pt[(n/2)].id<<endl;

return 0;
}