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,哪有那么复杂 ...
随机推荐
- 基于Visual C++2013拆解世界五百强面试题--题10-找出N个数种最大的K个数
有一亿个整数,请找出最大的 1000 个,要求时间越短越好, 空间占用越好越好. 如果不考虑时间效率,很容易想到解决方法,我们只需存储前一千个数, 然后依次读入后面的数和这一千个数组比较,替换其中比较 ...
- QT在ui文件上建立信号操机制会不会对后期维护产生影响 - love4Mario的专栏 - 博客频道 - CSDN.NETQT在ui文件上建立信号操机制会不会对后期维护产生影响 - love4Mario的专栏 - 博客频道 - CSDN.NET
QT在ui文件上建立信号操机制会不会对后期维护产生影响 - love4Mario的专栏 - 博客频道 - CSDN.NET QT在ui文件上建立信号操机制会不会对后期维护产生影响 分类: 学习心得 2 ...
- STC12C5201AD AD采样+串口发送模板
#include<reg52.h> sfr ADC_CONTR = 0xBC; //ADC control register sfr ADC_RES = 0xBD; //ADC 8-bit ...
- hdu5188 加限制的01背包问题
http://acm.hdu.edu.cn/showproblem.php? pid=5188 Problem Description As one of the most powerful brus ...
- 【iOS开发-52】假设要模仿练习,怎样找到其它应用程序的icon、使用框架等资源?
(1)在91助手等站点下载ipa格式的安装包.假设是安卓的应该是apk格式的.此处仅仅说iOS的.比方以下这个,下载到电脑. (2)然后,找到它,右击"归档",相当于解压. (3 ...
- No.3小白的HTML+CSS心得篇
A--看的东西多了总会出现好多模糊不清的又长的很像的的词语 今天对此进行区别分析下 1. align 与 text-align的区别 align 在W3Cschool中是这样解释的 ----alig ...
- CSS样式属性
一.背景与前景 1.背景: 2.前景字体: (二)边界和边框 border(表格边框.样式等).margin(表外间距).padding(内容与单元格间距). margin(外边距)对自身不会有变化, ...
- Java调用Oracle存储Package
Oracle的包Package中可以有很多存储,可通过该包的总调入口在java中直接调用. //java调用oracle的package代码 public boolean cal() throws j ...
- 「OC」block 和 protocol
一.block (一)简介 block 是什么?苹果推荐的类型,效率高,在运行中保存代码.用来封装和保存代码,有点像函数,block 可以在任何时候执行.在多线程.异步任务.集合遍历.集合排序.动 ...
- Resource is out of sync with the file system: 解决办法
在eclipse中,启动server时报此错,是因为文件系统不同步造成的,解决方法有两个: (1)选中工程,右键,选择F5(手动刷新): (2)Window->Preferences->G ...