USACO Ski Course Design 发表于 2016-03-31 | 分类于 USACO Training , Chapter 1 Getting started , Section 1.3 | Code12345678910111213141516171819202122232425262728293031323334353637383940414243444546/* ID: wcr19961 PROG: skidesign LANG: C++11 */#include <cstdio>#include <cstring>#include <algorithm>#include <cstdlib>#include <string>#include <set>using namespace std;typedef long long LL;const int inf = 0x3f3f3f3f;const int maxn = 110;int a[maxn];int main() { freopen("skidesign.in", "r", stdin); freopen("skidesign.out", "w", stdout); int n, ans = inf, l = 100, r = 0; scanf("%d", &n); for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); l = min(l, x), r = max(r, x); ++a[x]; } for (int i = l; i <= r; ++i) { int res = 0; for (int j = l; j <= r; ++j) { if (a[j] > 0) { if (j < i) { res += a[j] * (j - i) * (j - i); } if (j > i + 17) { res += a[j] * (j - i - 17) * (j - i - 17); } } } ans = min(ans, res); } printf("%d\n", ans); return 0;}