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.

————————————————————————题解

这题™辣么水为啥我提交了6次才过啊orz

我本不该对什么常数优化有什么期待……我一开始觉得应该是某个长为17区间,然后两边往那里靠,我觉得这个区间应该在中间

但是好像有些数据会被卡,然后我想起来range只有100

™我暴力枚举每个长为17的区间就好啦orz

:-(唉,好蒟蒻啊……

复杂度也只有106简直妥妥过嘛……

大意是一个农夫为了逃税要破坏自然,比如给山降低或给山增高,使得最大最小的山差值严格控制在17以内,包括17,降低或增高一个高度x的花费是x2,一个山只能修改一次高度

 /*
PROB: skidesign
LANG: C++
ID: jiaqi si
*/
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#define ivory
#define mo 1000000007
#define siji(i,x,y) for(int i=(x);i<=(y);i++)
#define gongzi(j,x,y) for(int j=(x);j>=(y);j--)
#define xiaosiji(i,x,y) for(int i=(x);i<(y);i++)
#define sigongzi(j,x,y) for(int j=(x);j>(y);j--)
#define pii pair<int,int>
#define fi first
#define se second
#define mo 1000000007
using namespace std;
int n;
int a[];
int ans;
int all=0x1f1f1f1f;
inline int o(int x) {return x*x;}
int main() {
#ifdef ivory
freopen("skidesign.in","r",stdin);
freopen("skidesign.out","w",stdout);
#else
freopen("f1.in","r",stdin);
#endif
scanf("%d",&n);
siji(i,,n) {scanf("%d",&a[i]);}
sort(a+,a+n+);
int l,r;
siji(i,,-) {
l=i;
r=l+;
ans=;
siji(i,,n) {
if(a[i]>r) ans+=o(a[i]-r);
if(a[i]<l) ans+=o(l-a[i]);
}
all=min(all,ans);
} printf("%d\n",all);
}

USACO 1.3 Ski Course Design的更多相关文章

  1. [题解]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 ...

  2. 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 ...

  3. USACO Section1.3 Ski Course Design 解题报告

    skidesign解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------ ...

  4. 洛谷 P3650 [USACO1.3]滑雪课程设计Ski Course Design

    P3650 [USACO1.3]滑雪课程设计Ski Course Design 题目描述 农民约翰的农场里有N座山峰(1<=N<=1000),每座山都有一个在0到100之间的整数的海拔高度 ...

  5. 【USACO 1.3】Ski Course Design

    n个点(n<=1000)大小范围[0,100],改变一些点的值,使得极差不超过17,代价为改变值的平方. 枚举修改后的最低高度low,维护最小代价. /* TASK: skidesign LAN ...

  6. USACO Ski Course Design 暴力

    从Min到Max范围内暴力一下即可. /* ID: wushuai2 PROG: skidesign LANG: C++ */ //#pragma comment(linker, "/STA ...

  7. USACO Section 1.3 Ski Course Design 解题报告

    题目 题目描述 有N座山,每座山都有一个高度,现在由于农夫想避税,所以想把这些山的高度进行一些改变,使得最高的山与最低的山之间的高度差不超过17.每座山最多只能改变一次高度,每次改变高度都会产生一定的 ...

  8. 「日常训练」「小专题·USACO」 Ski Course Design (1-4)

    题目 以后补 分析 mmp这题把我写蠢哭了 我原来的思路是什么呢? 每轮找min/max,然后两个决策:升min/降max 像这样子dfs找最优,然后花式剪枝 但是一想不对啊,这才1-4,哪有那么复杂 ...

  9. USACO 1.3.6 Ski Course Design[滑雪课程设计]

    先说说思路: 这题比上一道坑人的wormholes简单多了!我一看到这题,“XXX设计”,还以为要用到什么dp呢,没想到是水题 用两层循环,第一层循环相差17中的上界,第二层遍历所有的山峰计算答案.并 ...

随机推荐

  1. C语言之scarf函数

    一 基本用法 scanf函数:接收用户的输入 语法: scanf("格式化控制符",地址列表); 例: int num; scanf("%d",&num ...

  2. 转载 C#文件上传

     一.分析 本次博客,主要解决文件上传等一系列问题,将从两方面来论述,即1G以内文件和1G以上文件. 对于上传1G以内的文件,可以采用基本的三种上传方法:用Web控件FileUpload.html控件 ...

  3. Python 购物车----之用户部分

    知识点: 文件读,写操作,if 判断, for 循环 salary = input("输入你的工资:") bought_list = [] product_list = {} wi ...

  4. Linux之初体验

    预备作业03--我的Linux初体验 学习基于VirtualBox虚拟机安装Ubuntu图文教程在自己笔记本上安装Linux操作系统 一开始以为这个项目很简单,以往也在自己的笔记本上看教程安装过软件, ...

  5. Sipdroid实现SIP(五): 用Java实现的UserAgent

    I. 概述 UserAgent是SIP协议中的一个概念, 将"打电话"功能中的主叫和被叫逻辑上封装成UserAgent, 就像将"注册"功能的发起方和接收方封装 ...

  6. 主成分分析 R语言

    主成分分析(Principal Component Analysis,PCA), 是一种统计方法.通过正交变换将一组可能存在相关性的变量转换为一组线性不相关的变量,转换后的这组变量叫主成分. 原理: ...

  7. NOIP2014-提高组初赛C语言解析(选择填空题)

    第二十届全国青少年信息学奥林匹克联赛初赛 一.单项选择题(共 20 题,每题 1.5 分,共计 30 分.每题有且仅有一个正确选项) 1. 以下哪个是面向对象的高级语言( B ) A.汇编语言   B ...

  8. Tiny6410之MMU开启

    存储管理单元存储管理单元MMU概述 在ARM系统中,存储管理单元MMU主要完成以下工作:1.虚拟存储空间到物理存储空间的映射.在ARM中采用页式虚拟存储管理.他把虚拟地址空间分成一个个固定大小的块,每 ...

  9. DevExpress的SpinEdit控件无法输入数字的问题

    今天在发布程序后突然发现了这个问题,刚开始很莫名其妙的,因为在调试时从来没碰到过.然后经过测试发现,这个问题的原因和输入法有很大关系: 当你的输入法是中文状态时,是无法向框中输入数字的,此时只能点击上 ...

  10. form -转载于blfshiye

    Form API 表单API 文件夹 1.概述 2.亮点 3.使用方法 4.表单元素 4.1 基本表单元素 4.2 定制表单元素 5.经常使用函数 5.1  add_action_buttons($c ...