只有1000个数,每个数在0到100 之间,暴力可做。
/*
ID: modengd1
PROG: skidesign
LANG: C++
*/
#include <iostream>
#include <stdio.h>
#include <memory.h>
using namespace std;
int N;
int input[1000];
int main()
{
freopen("skidesign.in","r",stdin);
freopen("skidesign.out","w",stdout);
scanf("%d",&N);
long long ans,temp;
for(int i=0;i<N;i++)
{
scanf("%d",&input[i]);
}
ans=99999999;
for(int i=0;i<100;i++)
{
temp=0;
int low=i,high=i+17;
for(int j=0;j<N;j++)
{
if(input[j]<low)
temp+=(low-input[j])*(low-input[j]);
else if(input[j]>high)
temp+=(input[j]-high)*(input[j]-high);
}
ans=min(ans,temp);
}
cout << ans << endl;
return 0;
}
原文:http://www.cnblogs.com/modengdubai/p/4764659.html