C++
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <algorithm>
using namespace std;
struct Pos{
int x;
int y;
int idx;
};
int N;
long long x_[500010],y_[500010];
Pos pos_x[500010];
Pos pos_y[500010];
long long dist[500010];
int comp_x(Pos a,Pos b){
if(a.x==b.x){
return a.y<b.y;
}
return a.x<b.x;
}
int comp_y(Pos a,Pos b){
if(a.y==b.y){
return a.x<b.x;
}
return a.y<b.y;
}
int main()
{
scanf("%d",&N);
for(int i=1;i<=N;i++){
int a,b;
scanf("%d %d",&a,&b);
pos_x[i].x=a;
pos_x[i].y=b;
pos_x[i].idx=i;
pos_y[i].x=a;
pos_y[i].y=b;
pos_y[i].idx=i;
}
sort(pos_x+1,pos_x+N+1,comp_x);
sort(pos_y+1,pos_y+N+1,comp_y);
for(int i=1;i<=N;i++){
x_[i]=pos_x[i].x+x_[i-1];
y_[i]=pos_y[i].y+y_[i-1];
}
long long min_=LLONG_MAX;
int result=0;
for(int i=1;i<=N;i++){
int idx_x=pos_x[i].idx;
int idx_y=pos_y[i].idx;
dist[idx_x]+=(long long)pos_x[i].x*(i-1)-x_[i-1]+x_[N]-x_[i]-(long long)pos_x[i].x*(N-i);
dist[idx_y]+=(long long)pos_y[i].y*(i-1)-y_[i-1]+y_[N]-y_[i]-(long long)pos_y[i].y*(N-i);
}
for(int i=1;i<=N;i++){
//printf("%lld\n",dist[i]);
if(dist[i]<min_){
result=i;
min_=dist[i];
}
}
printf("%d",result);
return 0;
}
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
공지 | 안내사항 | 관리자 | 2019.12.21 | 163 |
74 | 9663 | 관리자 | 2019.12.21 | 114 |
73 | 9345 | 관리자 | 2020.04.11 | 150 |
72 | 9019 | 관리자 | 2019.12.21 | 113 |
71 | 7569 | 관리자 | 2019.12.21 | 113 |
70 | 6987 | 관리자 | 2019.12.21 | 113 |
69 | 5842 | 관리자 | 2020.04.11 | 151 |
68 | 5625 | 관리자 | 2019.12.21 | 109 |
67 | 5419 | 관리자 | 2020.04.11 | 155 |
66 | 3392 | 관리자 | 2020.04.11 | 156 |
65 | 3019 | 관리자 | 2019.12.21 | 111 |
64 | 2933 | 관리자 | 2019.12.21 | 112 |
63 | 2931 | 관리자 | 2019.12.21 | 111 |
62 | 2836 | 관리자 | 2019.12.21 | 110 |
61 | 2667 | 관리자 | 2019.12.21 | 113 |
60 | 2636 | 관리자 | 2019.12.21 | 113 |
59 | 2629 | 관리자 | 2020.04.11 | 146 |
58 | 2615 | 관리자 | 2019.12.21 | 111 |
57 | 2610 | 관리자 | 2020.04.11 | 146 |
56 | 2606 | 관리자 | 2019.12.21 | 111 |
55 | 2585 | 관리자 | 2019.12.21 | 113 |
54 | 2578 | 관리자 | 2019.12.21 | 111 |
53 | 2573 | 관리자 | 2020.04.11 | 151 |
52 | 2557 | 관리자 | 2019.12.21 | 111 |
51 | 2512 | 관리자 | 2019.12.21 | 111 |
50 | 2504 | 관리자 | 2020.04.11 | 147 |
49 | 2481 | 관리자 | 2019.12.21 | 112 |
48 | 2478 | 관리자 | 2020.04.11 | 148 |
47 | 2473 | 관리자 | 2020.04.11 | 153 |
46 | 2470 | 관리자 | 2020.04.11 | 151 |