题目请点我
题解:
水题,不会超时。枚举标准起点就可以。
代码实现:
/*
ID: eashion
LANG: C++
TASK: skidesign
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define MAX 1010
#define LL long long
#define INF 0x7fffffff
using namespace std;
int N;
LL res;
int len[MAX];
int low_B,high_B;
LL gets(int pos);
int main()
{
freopen("skidesign.in","r",stdin);
freopen("skidesign.out","w",stdout);
while( scanf("%d",&N) != EOF ){
res = INF;
memset(len,0,sizeof(len));
for( int i = 0 ; i < N; i++ ){
scanf("%d",&len[i]);
}
sort(len,len+N);
for( int i = 1; i <= len[N-1]-17; i++ ){
LL tmp = gets(i);
if( tmp < res ){
res = tmp;
}
}
cout<<res<<endl;
}
return 0;
}
LL gets(int pos){
low_B = pos;
high_B = pos+17;
LL tres = 0;
for( int i = 0; i < N; i++ ){
if( len[i] < low_B ){
tres += (low_B-len[i])*(low_B-len[i]);
}
if( len[i] > high_B ){
tres += (len[i]-high_B)*(len[i]-high_B);
}
}
return tres;
}