3 条题解
-
2赵青海 (huhe) LV 7 SU @ 2021-8-7 19:00:37
C++ :
#include <iostream> #include <algorithm> using namespace std; const int N = 10010; int n; int x[N], y[N]; int work(int *q) // *q等价于q[0] { int res = 0; sort(q, q + n); for(int i = 0; i < n; i++) res += abs(q[i] - q[i / 2]); //下标从0开始 i/2下取整 return res; } int main() { cin >> n; for(int i = 0; i < n; i++) cin >> x[i] >> y[i]; sort(x, x + n); for(int i = 0; i < n; i++) x[i] -= i; cout << work(y) + work(x) << endl; return 0; }
-
12023-5-13 12:52:59@
/***************** 备注: *****************/ #include <iostream> #include <iomanip> #include <cmath> #include <cstring> #include <algorithm> #include <cstdio> #include <queue> using namespace std; #define LL long long #define MAXM 3010 #define MAXN 3010 const int INF =0x3f3f3f3f; const int N = 10010; int n; int x[N], y[N]; int work(int *q) { int res = 0; sort(q, q + n); for(int i = 0; i < n; i++) res += abs(q[i] - q[i / 2]); return res; } int main() { cin >> n; for(int i = 0; i < n; i++) cin >> x[i] >> y[i]; sort(x, x + n); for(int i = 0; i < n; i++) x[i] -= i; cout << work(y) + work(x) << endl; return 0; }
-
12021-11-28 19:30:48@
#include <iostream> #include <algorithm> using namespace std; const int N = 10010; int n; int x[N], y[N]; int work(int *q) // *q等价于q[0] { int res = 0; sort(q, q + n); for(int i = 0; i < n; i++) res += abs(q[i] - q[i / 2]); //下标从0开始 i/2下取整 return res; } int main() { cin >> n; for(int i = 0; i < n; i++) cin >> x[i] >> y[i]; sort(x, x + n); for(int i = 0; i < n; i++) x[i] -= i; cout << work(y) + work(x) << endl; return 0; }
- 1
信息
- ID
- 34
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 1
- 标签
- 递交数
- 69
- 已通过
- 62
- 上传者