首页 > 其他 > 详细

usaco Ski Course Design

时间:2015-08-27 22:40:43      阅读:296      评论:0      收藏:0      [点我收藏+]

只有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;
}

  

usaco Ski Course Design

原文:http://www.cnblogs.com/modengdubai/p/4764659.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!