AcWing 1353. 滑雪场设计
原题链接
简单
作者:
NeonSean
,
2021-01-25 19:24:17
,
所有人可见
,
阅读 292
#include <iostream>
#include <limits.h>
#include <algorithm>
using namespace std;
const int N = 1005;
int a[N];
inline int mypow(int t) {
return t * t;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i ++) cin >> a[i];
int res = INT_MAX;
for (int i = 1 ; i < 84; i++) {
int l = i, r = i + 17;
int temp = 0;
for (int j = 0; j < n; j ++) {
if (a[j] < l) temp += mypow(a[j] - l);
else if (a[j] > r) temp += mypow(a[j] - r);
}
res = min(res, temp);
}
cout << res << endl;
return 0;
}