zoukankan      html  css  js  c++  java
  • USACO Ski Course Design 暴力

    从Min到Max范围内暴力一下即可。

    /*
    ID: wushuai2
    PROG: skidesign
    LANG: C++
    */
    //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
    #include <stdio.h>
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <cmath>
    #include <stack>
    #include <string>
    #include <map>
    #include <set>
    #include <list>
    #include <queue>
    #include <vector>
    #include <algorithm>
    #define Max(a,b) (((a) > (b)) ? (a) : (b))
    #define Min(a,b) (((a) < (b)) ? (a) : (b))
    #define Abs(x) (((x) > 0) ? (x) : (-(x)))
    #define MOD 1000000007
    #define pi acos(-1.0)
    
    using namespace std;
    
    typedef long long           ll      ;
    typedef unsigned long long  ull     ;
    typedef unsigned int        uint    ;
    typedef unsigned char       uchar   ;
    
    template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
    template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;}
    
    const double eps = 1e-7      ;
    const int M = 200000         ;
    const ll P = 10000000097ll   ;
    const int INF = 0x3f3f3f3f   ;
    const int MAX_N = 20         ;
    
    int a[1011];
    
    int main() {
        ofstream fout ("skidesign.out");
        ifstream fin ("skidesign.in");
        int i, j, k, t, n, m, s, c, w, q;
        fin >> n;
        int Min = INF, Max = -INF;
        int ans = INF;
        for(i = 0; i < n; ++i){
            fin >> a[i];
            checkmax(Max, a[i]);
            checkmin(Min, a[i]);
    
        }
        for(int low = Min; low < Max; ++low){
            for(int high = low + 1; high <= Max; ++high){
                if(Abs(high - low) <= 17){
                    int cur = 0;
                    for(i = 0; i < n; ++i){
                        if(a[i] < low){
                            cur += (low - a[i]) * (low - a[i]);
                        } else if(a[i] > high){
                            cur += (a[i] - high) * (a[i] - high);
                        }
                    }
                    checkmin(ans, cur);
                }
            }
        }
        fout << ans << endl;
        fin.close();
        fout.close();
        return 0;
    }
  • 相关阅读:
    基础总结篇之三:Activity的task相关
    基础总结篇之一:Activity生命周期
    基础总结篇之二:Activity的四种launchMode
    SAP_清除默认Action
    FICO_Delete error message
    FICO_无法生成凭证(System status CLSD is active (WBS K/A6020372-205-KCCL))
    FICO_导出8月KOB3报表
    FICO_更改BP
    FICO_月末关帐
    SAP_清除默认导出格式
  • 原文地址:https://www.cnblogs.com/wushuaiyi/p/4253914.html
Copyright © 2011-2022 走看看