'commit'
This commit is contained in:
24
TangDou/CSP-J/AcWingTraining/T5/P1889.cpp
Normal file
24
TangDou/CSP-J/AcWingTraining/T5/P1889.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 10010;
|
||||
int x[N], y[N];
|
||||
|
||||
int n, res;
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
|
||||
|
||||
sort(y, y + n);
|
||||
sort(x, x + n);
|
||||
|
||||
for (int i = 0; i < n; i++) res += abs(y[i] - y[n / 2]); // 对与x轴的一条平等线的最短距离和
|
||||
|
||||
for (int i = 0; i < n; i++) x[i] -= i;
|
||||
|
||||
sort(x, x + n);
|
||||
for (int i = 0; i < n; i++) res += abs(x[i] - x[n / 2]);
|
||||
|
||||
// 输出
|
||||
cout << res << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user