码迷,mamicode.com
首页 > 其他好文 > 详细

usaco Ski Course Design

时间:2015-08-27 22:42:41      阅读:141      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!