USACO 1.3 Ski Course Design

今晚,看了一整晚的电影,下载了一整晚的$GTA4$(13G啊 卧槽。。。),额最近迅雷好像很不给力,下载速度很慢,外加今天考了六级,听力真是跪死-。-,

                                  clip_image001

睡觉前做了一道$usaco$,最近很少做题啊QAQ

===========================华丽的主题分割线===========================

暴力直接枚举,让$i$从$1$~$83$循环,每次假设最小值为$i$,然后在所有的$hill$的高度那里判断就OK

 

/*
ID:jusonal1
PROG:skidesign
LANG:C++
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 1111;
int n;
int a[maxn];
int main()
{
    freopen("skidesign.in","r",stdin);
    freopen("skidesign.out","w",stdout);
    while(~scanf("%d",&n)) {
        int ans = 0x3f3f3f3f,tmp;
        for(int i = 1;i <= n;++i) scanf("%d",&a[i]);
        for(int i = 1;i <= 100 -17;++i) {
               tmp = 0;
            for(int j = 1;j <= n;++j) {
                if(a[j] < i) tmp += (a[j]-i)*(a[j]-i);
                if(a[j] > i+17) tmp += (a[j]-i-17)*(a[j]-i-17);
            }
            ans = min(tmp,ans);
        }
        printf("%d\n",ans);
    }
    return 0;
}
posted @ 2014-12-21 02:53  jusonalien  阅读(264)  评论(0编辑  收藏  举报