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,哪有那么复杂 ...
随机推荐
- ASP.NET jQuery 随笔 使用allValidator插件简单实现客户端验证功能
首先放出该插件的下载地址:http://pan.baidu.com/s/1Aa3yD,里面有帮助文档,详细了解可以自行下载学习,本章只讲解一些基本的验证功能,页面代码如下: <%@ Page L ...
- Windows下Python中的中文路径和中文输出问题
这几天有个项目需要写一点类似于脚本的小程序,就用Python写了,涉及到中文路径和中文输出的问题,整理一下. 有一个问题我觉得需要先强调一下,在写Python程序的时候,一定保证编码是utf-8,然后 ...
- net-snmp启用python模块
1. http://blog.jeoygin.org/2011/09/centos-5-install-python-2-6-and-python-setuptools-2-6.html 2. htt ...
- S50卡
产品名称:Mifare 1K(S50)卡 芯片类型:Philips Mifare 1 IC S50 存储容量:8Kbit,16个分区,每分区两组密码 工作频率:13.56 MHz 通讯速率:106KB ...
- Noip2011提高组总结
这套题思考的难度比较大,应该说是有四题基础题,一题比较复杂的搜索加模拟,还有一题需要深度思考一下.自己的代码漏洞还是很大,而且思考的时候会遗漏一些情况,这些错误都是致命的,去年Noip的惨败也证实了这 ...
- MySql学习笔记(转载)
. 数值类型 -- a. 整型 ---------- 类型 字节 范围(有符号位) tinyint 1字节 - ~ ...
- golang(2):beego 环境搭建
本文的原文连接是: http://blog.csdn.net/freewebsys/article/details/46695513 转载请一定注明出处. 1,关于beego beego是一个用Go开 ...
- URlRewriter组件下载及使用说明
下载地址:http://www.chx99.cn/file/URLRewriter.rar在web.config添加如下配置节: <httpHandlers> <add ver ...
- UILabel显示html文本
NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\ ...
- jsp中的jquery失效以及引入js失败的问题
这段时间在试着看公司用的框架是怎么写的,看到项目中对jquery进一步封装的这一部分,所以自己试着写一些demo来模仿框架中的用法. 再一次的,又遇到了一个问题,jsp中引入js的问题,好久没有自己从 ...