https://www.luogu.org/discuss/lists?forumname=3650#newpost

P3650 [USACO1.3] 滑雪课程设计Ski Course Design

额请无视freopen
by 违规用户名24059 @ 2017-11-10 15:06:50


@[大膜导师](/space/show?uid=24059) 先举个栗子 ```cpp 2 0 34 ``` 实际上最小是145 即把0改成8 把34改成25 也就是说 最小高度不一定在输入中出现过 给出我的代码(O(MAXH * MAXH),即O(10000))仅供参考 ```cpp /* ID:louhanc1 LANG:C++ TASK:skidesign */ #include<cstdio> #include<map> #include<string> #include<iostream> #include<cctype> #include<cstring> #include<algorithm> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdlib> using namespace std; inline int read(){ int ans(0); char t(getchar()); bool flg(0); while( !isdigit(t) ) { if ( t == '-' ) flg = 1; t = getchar(); } while( isdigit(t) ){ ans = ans * 10 + ( t ^ '0' ); t = getchar(); } if ( flg ) return -ans; return ans; } int N; int h[105], res(0x7f7f7f7f); int main(){ // freopen( "skidesign.in", "r", stdin ); // freopen( "skidesign.out", "w", stdout ); N = read(); for ( int i = 1; i <= N; ++i ) h[read()]++; for ( int maxh = 17; maxh <= 100; ++maxh ){ int minh = maxh - 17, now(0); for ( int j = 0; j < minh; ++j ) now += h[j] * ( minh - j ) * ( minh - j ); for ( int j = maxh + 1; j <= 100; ++j ) now += h[j] * ( j - maxh ) * ( j - maxh ); res = min( res, now ); } printf( "%d\n", res ); return 0; } ```
by _louhc @ 2018-07-01 15:45:50


|