题目链接:
/
#include <iostream>
#include <cstring>
#include <algorithm>using namespace std;const int N = 1010;int n;
int h[N];int main()
{cin >> n;for (int i = 0; i < n; i ++ ) cin >> h[i];int res = 1e8;//最大值是1e7 多取一位for (int i = 0; i + 17 <= 100; i ++ )//枚举所有区间{int cost = 0, l = i, r = i + 17;//l是左区间 r是右区间for (int j = 0; j < n; j ++ )//修改所有山峰的代价之和if (h[j] < l) cost += (l - h[j]) * (l - h[j]);//在l 左区间else if (h[j] > r) cost += (h[j] - r) * (h[j] - r);//在r 右区间res = min(res, cost);}cout << res << endl;return 0;
}
本文发布于:2024-01-28 18:34:05,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17064380509425.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |