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- ;
const int M = ;
const ll P = 10000000097ll ;
const int INF = 0x3f3f3f3f ;
const int MAX_N = ; int a[]; 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 = ; 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 + ; high <= Max; ++high){
if(Abs(high - low) <= ){
int cur = ;
for(i = ; 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 ;
}
USACO Ski Course Design 暴力的更多相关文章
- USACO 1.3 Ski Course Design - 暴力
Ski Course Design Farmer John has N hills on his farm (1 <= N <= 1,000), each with an integer ...
- USACO Ski Course Design解析和C语言实现
题目大意: John农场有N(1=<N<=1000)小丘陵(山),它们高度的范围从0 到 100 但仅仅有当最大的高度差不大于17时.才干够避税.John对它们进行改造,从高的丘陵上取土放 ...
- USACO Ski Course Design
洛谷P3650 https://www.luogu.org/problemnew/show/P3650 JDOJ 2393 https://neooj.com:8082/oldoj/problem.p ...
- [题解]USACO 1.3 Ski Course Design
Ski Course Design Farmer John has N hills on his farm (1 <= N <= 1,000), each with an integer ...
- USACO 1.3 Ski Course Design
Ski Course Design Farmer John has N hills on his farm (1 <= N <= 1,000), each with an integer ...
- 洛谷 P3650 [USACO1.3]滑雪课程设计Ski Course Design
P3650 [USACO1.3]滑雪课程设计Ski Course Design 题目描述 农民约翰的农场里有N座山峰(1<=N<=1000),每座山都有一个在0到100之间的整数的海拔高度 ...
- 【USACO 1.3】Ski Course Design
n个点(n<=1000)大小范围[0,100],改变一些点的值,使得极差不超过17,代价为改变值的平方. 枚举修改后的最低高度low,维护最小代价. /* TASK: skidesign LAN ...
- USACO Section 1.3 Ski Course Design 解题报告
题目 题目描述 有N座山,每座山都有一个高度,现在由于农夫想避税,所以想把这些山的高度进行一些改变,使得最高的山与最低的山之间的高度差不超过17.每座山最多只能改变一次高度,每次改变高度都会产生一定的 ...
- 「日常训练」「小专题·USACO」 Ski Course Design (1-4)
题目 以后补 分析 mmp这题把我写蠢哭了 我原来的思路是什么呢? 每轮找min/max,然后两个决策:升min/降max 像这样子dfs找最优,然后花式剪枝 但是一想不对啊,这才1-4,哪有那么复杂 ...
随机推荐
- sourceTree安装与使用
1,下载并安装 sourceTree http://downloads.atlassian.com/software/sourcetree/windows/SourceTreeSetup_1.6.14 ...
- python初探-collections容器数据类型
collections容器数据类型是对基本数据类型的补充,简单介绍下计数器.有序字典.默认字典.可命名元祖.队列. 计数器(Counter) Counter是对字典类型的补充,用于追踪值得出现次数 c ...
- 【转】关于UItableViewCell的accessoryType属性
转载自:http://blog.csdn.net/kmyhy/article/details/6442351 使用的话,例如: cell.accessoryType = UITableViewCell ...
- ORA-20000: ORU-10027: buffer overflow, limit of 10000 bytes
要用dbms_output.put_line来输出语句,遇到以下错误: ERROR 位于第 1 行: ORA-20000: ORU-10027: buffer overflow, limit ...
- C#中WebClient使用DownloadString中文乱码的解决办法
原文:C#中WebClient中文乱码的解决办法 第一次尝试: string question = textBox1.Text.ToString(); WebClient client= new We ...
- android怎样自定义设置下拉列表样式
图样: 实现方式: 1.水平布局一个TextView和一个ImageView(小黑箭头) 2.实现点击ImageView的单击事件,弹出PopupWindow 3.PopupWindow中实现下拉列表 ...
- pyrailgun 0.24 : Python Package Index
pyrailgun 0.24 : Python Package Index pyrailgun 0.24 Download pyrailgun-0.24.zip Fast Crawler For Py ...
- Cow Acrobats(贪心)
Cow Acrobats Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3686 Accepted: 1428 Desc ...
- Spring MVC遭遇checkbox的问题解决方式
Spring MVC遭遇checkbox的问题是:当checkbox全不选时候,则该checkbox域的变量为null,不能动态绑定到spring的controller方法的入參上,并抛出异常. 解决 ...
- Objective-c 方法的调用
在书写了类的声明和实现后,应用程序如何去调用它呢? 在Objective-c中,调用方法的简单格式如下: 1⃣ [实例 方法]; 如: [person setAge:32]; 其中 pe ...