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 elevation in the range 0 .. 100. In the winter, since there is abundant snow on these hills, FJ routinely operates a ski training camp.
Unfortunately, FJ has just found out about a new tax that will be assessed next year on farms used as ski training camps. Upon careful reading of the law, however, he discovers that the official definition of a ski camp requires the difference between the highest and lowest hill on his property to be strictly larger than 17. Therefore, if he shortens his tallest hills and adds mass to increase the height of his shorter hills, FJ can avoid paying the tax as long as the new difference between the highest and lowest hill is at most 17.
If it costs x^2 units of money to change the height of a hill by x units, what is the minimum amount of money FJ will need to pay? FJ can change the height of a hill only once, so the total cost for each hill is the square of the difference between its original and final height. FJ is only willing to change the height of each hill by an integer amount.
PROGRAM NAME: skidesign
INPUT FORMAT:
Line 1: | The integer N. |
Lines 2..1+N: | Each line contains the elevation of a single hill. |
SAMPLE INPUT (file skidesign.in):
5
20
4
1
24
21
INPUT DETAILS:
FJ's farm has 5 hills, with elevations 1, 4, 20, 21, and 24.
OUTPUT FORMAT:
The minimum amount FJ needs to pay to modify the elevations of his hills so the difference between largest and smallest is at most 17 units.
Line 1: |
SAMPLE OUTPUT (file skidesign.out):
18
OUTPUT DETAILS:
FJ keeps the hills of heights 4, 20, and 21 as they are. He adds mass to the hill of height 1, bringing it to height 4 (cost = 3^2 = 9). He shortens the hill of height 24 to height 21, also at a cost of 3^2 = 9.
Submission file Name: USACO Gateway | Comment or Question
(转自[USACO])
首先讲一下题目大意。有N座山峰,每座山峰的高度大于等于0小于等于100,由于下了雪,所以可以改造成滑雪场(倾盆大雪),但是如果最高的山峰和最低的山峰高度之差大于17政府就要收税,John为了不被收费,就决定改造山峰。把一座山峰的高度改动x,就会产生x2的费用。求最小的费用。
鉴于数据范围较小,于是决定暴力,枚举改造后的最小高度,然后暴力每次跑一遍就可以了
Code
/*
ID:
PROG: skidesign
LANG: C++11
*/
/**
* USACO
* Accepted
* Time:0ms
* Memory:4180k
*/
#include<iostream>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
typedef bool boolean;
#define INF 0xfffffff
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
template<typename T>
inline void readInteger(T& u){
char x;
int aFlag = ;
while(!isdigit((x = getchar())) && x != '-');
if(x == '-'){
x = getchar();
aFlag = -;
}
for(u = x - ''; isdigit((x = getchar())); u = (u << ) + (u << ) + x - '');
ungetc(x, stdin);
u *= aFlag;
} int n;
int *hills; inline void init(){
readInteger(n);
hills = new int[(const int)(n + )];
for(int i = ; i <= n; i++){
readInteger(hills[i]);
}
} int result = INF;
inline void solve(){
for(int res = ; res <= ; res++){
int cmp = ;
for(int i = ; i <= n; i++){
if(hills[i] < res){
cmp += (res - hills[i]) * (res - hills[i]);
}else if(hills[i] > res + ){
cmp += (hills[i] - res - ) * (hills[i] - res - );
}
}
smin(result, cmp);
}
printf("%d\n", result);
} int main(){
freopen("skidesign.in", "r", stdin);
freopen("skidesign.out", "w", stdout);
init();
solve();
return ;
}
USACO 1.3 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 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 暴力
从Min到Max范围内暴力一下即可. /* ID: wushuai2 PROG: skidesign LANG: C++ */ //#pragma comment(linker, "/STA ...
- USACO Section1.3 Ski Course Design 解题报告
skidesign解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------ ...
- 洛谷 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,哪有那么复杂 ...
- USACO 1.3.6 Ski Course Design[滑雪课程设计]
先说说思路: 这题比上一道坑人的wormholes简单多了!我一看到这题,“XXX设计”,还以为要用到什么dp呢,没想到是水题 用两层循环,第一层循环相差17中的上界,第二层遍历所有的山峰计算答案.并 ...
随机推荐
- Oracle管理监控之sql developer配置与简单使用
1. 前提:使用sqldeveloper的前提是你的机器上安装了Oracle. 2. 刚打开sql developer 找到所安装的jdk的目录,本人安装的路径为:C:\Java\jdk1.6.0\b ...
- The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path:
运行环境: Intellij idea 14 在改了项目名称. 运行时候出现了 The APR based Apache Tomcat Native library which allows opti ...
- mybatis中大于等于、小于等于的写法
在xml格式中,常常会遇到xml解析sql时候出错,这个时候需要用其他符号来表示.在mybatis中会遇到,需要做如下的转换:
- 【python+opencv】直线检测+圆检测
Python+OpenCV图像处理—— 直线检测 直线检测理论知识: 1.霍夫变换(Hough Transform) 霍夫变换是图像处理中从图像中识别几何形状的基本方法之一,应用很广泛,也有很多改进 ...
- flask-WTForms组件
WTForms是一个支持多个web框架的form组件 主要能够帮助我们生成html标签 对数据进行验证 安装 pip install wtforms Wtforms的使用 这里借助一个用户登录注册的示 ...
- javaScript高级教程(二)Scope Chain & Closure Example
<!DOCTYPE html> <html> <head> <meta charset=gb2312 /> <title>js</ti ...
- .NET数据挖掘与机器学习开源框架
1. 数据挖掘与机器学习开源框架 1.1 框架概述 1.1.1 AForge.NET AForge.NET是一个专门为开发者和研究者基于C#框架设计的,他包括计算机视觉与人工智能,图像处理,神经 ...
- 知道椭圆长轴,短轴长度,ab直线的长度知道且垂直于长轴。求ab的弧长。
1:知道椭圆长轴,短轴长度,ab直线的长度知道且垂直于长轴.求ab的弦长.: https://jingyan.baidu.com/article/a378c960a5af27b3282830e6.ht ...
- [dt]世纪历史长河年代表
年代口诀 夏商与西周, 东周分两段, 春秋和战国, 一统秦两汉, 三分魏蜀吴, 二晋前后延, 南北朝并列, 隋唐五代传, 宋元明清后, 皇朝至此完. 中国历史长河年代表 参考: 中国历史朝代顺序表.年 ...
- iOS 开发笔记-plist使用
1.创建一个plist 2.填写为ImageList.plist 3.填入数据 4.完成 加载代码: @interface UYViewController () //图片信息的数组 @propert ...