首页 > 代码库 > USACO Ski Course Design 暴力
USACO Ski Course Design 暴力
从Min到Max范围内暴力一下即可。
/*ID: wushuai2PROG: skidesignLANG: 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;}
USACO Ski Course Design 暴力
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。