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 | 173 |
| 45 | 2468 | 관리자 | 2019.12.21 | 8 |
| 44 | 2458 | 관리자 | 2020.04.11 | 44 |
| 43 | 2457 | 관리자 | 2020.04.11 | 47 |
| 42 | 2454 | 관리자 | 2020.04.11 | 43 |
| 41 | 2450 | 관리자 | 2020.04.11 | 40 |
| 40 | 2339 | 관리자 | 2020.04.11 | 41 |
| 39 | 2307 | 관리자 | 2019.12.21 | 8 |
| 38 | 2250 | 관리자 | 2019.12.21 | 8 |
| 37 | 2233 | 관리자 | 2019.12.21 | 6 |
| 36 | 2170 | 관리자 | 2019.12.21 | 7 |
| 35 | 2132 | 관리자 | 2019.12.21 | 7 |
| 34 | 2096 | 관리자 | 2019.12.21 | 8 |
| 33 | 2042 | 관리자 | 2020.04.11 | 45 |
| 32 | 2003 | 관리자 | 2020.04.11 | 39 |
| 31 | 1991 | 관리자 | 2019.12.21 | 8 |
| 30 | 1967 | 관리자 | 2019.12.21 | 6 |
| 29 | 1966 | 관리자 | 2020.04.11 | 45 |
| 28 | 1946 | 관리자 | 2020.04.11 | 39 |
| 27 | 1874 | 관리자 | 2020.04.11 | 43 |
| 26 | 1839 | 관리자 | 2020.04.11 | 44 |
| 25 | 17611 | 관리자 | 2019.12.21 | 7 |
| 24 | 1753 | 관리자 | 2019.12.21 | 8 |
| 23 | 1742 | 관리자 | 2020.04.11 | 6 |
| 22 | 1720 | 관리자 | 2020.04.11 | 6 |
| » | 16210 | 관리자 | 2020.04.11 | 57 |
| 20 | 16201 | 관리자 | 2020.04.11 | 44 |
| 19 | 15971 | 관리자 | 2019.12.21 | 6 |
| 18 | 14865 | 관리자 | 2019.12.21 | 8 |
| 17 | 14503 | 관리자 | 2019.12.21 | 7 |
| 16 | 14502 | 관리자 | 2019.12.21 | 6 |