Best Cow Fences
题目描述
FJ wants to build a fence around a contiguous group of these fields in order to maximize the average number of cows per field within that block. The block must contain at least F (1 <= F <= N) fields, where F given as input.
Calculate the fence placement that maximizes the average, given the constraint.
输入
* Lines 2..N+1: Each line contains a single integer, the number of cows in a field. Line 2 gives the number of cows in field 1,line 3 gives the number in field 2, and so on.
输出
样例输入
10 6
6
4
2
10
3
8
5
9
4
1
样例输出
6500
分析:据说可以斜率DP,看别人题解的时候觉得很有道理,但是就是WA可还行。后来被逼无奈二分答案+DP了。
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#define range(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
int n,f;
double ss[],aa[],Left=0x7fffffff,Right;
void init(){
cin>>n>>f;
range(i,,n){
cin>>aa[i];
ss[i]+=ss[i-]+aa[i];
Left=min(Left,aa[i]);
Right=max(Right,aa[i]);
}
}
bool judge(double val){
double tmp,pre=ss[f-]-(f-)*val;
range(i,f,n){
tmp=(ss[i]-ss[i-f])-f*val;
pre+=aa[i]-val;
pre=max(tmp,pre);
if(pre>-1e-)return true;
}
return false;
}
void solve(){
while(Right-Left>1e-){
double mid=(Right+Left)/;
if(judge(mid))Left=mid;
else Right=mid;
}
cout<<(int)(Right*)<<endl;
}
int main() {
init();
solve();
return ;
}
Best Cow Fences的更多相关文章
- POJ 2018 Best Cow Fences(二分+最大连续子段和)
Best Cow Fences Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14601 Accepted: 4720 Desc ...
- POJ-2018 Best Cow Fences(二分加DP)
Best Cow Fences Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10174 Accepted: 3294 Desc ...
- POJ2018 Best Cow Fences —— 斜率优化DP
题目链接:https://vjudge.net/problem/POJ-2018 Best Cow Fences Time Limit: 1000MS Memory Limit: 30000K T ...
- 一本通 1434:【例题2】Best Cow Fences
Best Cow Fences 二分答案 + 前缀和 个人认为题意没有表述清楚,本题要求的是满足题意的连续子序列(难度大大降低了有木有). 本题的精度也是非常令人陶醉,请您自行体会吧! #includ ...
- 1434:【例题2】Best Cow Fences
1434:[例题2]Best Cow Fences 时间限制: 1000 ms 内存限制: 65536 KB提交数: 263 通过数: 146 [题目描述] 给定一个长度为n的 ...
- loj#10012\poj2018 Best Cow Fences(二分)
题目 #10012 「一本通 1.2 例 2」Best Cow Fences 解析 有序列\(\{a_i\}\),设\([l,r]\)上的平均值为\(\bar{x}\),有\(\sum_{i=l}^r ...
- Poj 2018 Best Cow Fences(分数规划+DP&&斜率优化)
Best Cow Fences Time Limit: 1000MS Memory Limit: 30000K Description Farmer John's farm consists of a ...
- POJ 2018 Best Cow Fences (二分答案构造新权值 or 斜率优化)
$ POJ~2018~Best~Cow~ Fences $(二分答案构造新权值) $ solution: $ 题目大意: 给定正整数数列 $ A $ ,求一个平均数最大的长度不小于 $ L $ 的子段 ...
- [USACO2003][poj2018]Best Cow Fences(数形结合+单调队列维护)
http://poj.org/problem?id=2018 此乃神题……详见04年集训队论文周源的,看了这个对斜率优化dp的理解也会好些. 分析: 我们要求的是{S[j]-s[i-1]}/{j-(i ...
- Poj2018 Best Cow Fences
传送门 题目大意就是给定一个长度为 n 的正整数序列 A ,求一个平均数最大的,长度不小于 L 的子序列. 思路: 二分答案. Code: #include<iostream> #incl ...
随机推荐
- Ubuntu下的定时备份数据库
1.编写备份数据库的shell脚本 mysqldump -uUserName -pPassword dbName >/XXX/XXXX/XXXX/fileName_$(date +%Y%m%d_ ...
- dotnet core 2.2 安装后在vs2017中无法选择 dotnet core 2.2 为目标框架
可能有效的解决方案: 无法完全保证有效,因为我本地装上没问题,只帮同事解决过一次,貌似有效 方案就是多装几个 .net core 2.2.xxx 版本,然后可能就正常识别了. 在安装之前,先把 vs ...
- 剖析微软Hyper-V的最佳部署方式
剖析微软Hyper-V的最佳部署方式 2014-04-24 10:53 布加迪编译 51CTO.com 字号:T | T 微软Hyper-V有两种不同的版本.既可以安装到Windows Server的 ...
- App 设计技巧
http://www.360doc.com/content/14/1120/18/21412_426730809.shtml http://veryui.diandian.com/post/2013- ...
- Excel动画教程50例(一)
Excel动画教程50例(一) 1.自动筛选 2.在Excel中字符替换 3.在Excel中冻结行列标题 4.在Excel中为导入外部数据 5.在Excel中行列快速转换 6.共享Excel工作簿 7 ...
- Google Optimize 安装使用教程
Google Optimize 介绍 打开链接 https://optimize.google.com/optimize/signup/ 填入电邮地址后等待注册邀请 Google Optimize是什 ...
- 我爱学 Python 之文件
读取文件 假设你已经在某个文件夹下创建了 "test.txt" 文件,且里面有一些内容,那你在当前位置输入 Python3,进入到交互模式,然后执行下面的操作: >>& ...
- c#每循环100次提交一次数据,最后一次不足100次提交一次
StringBuilder sb=new StringBuilder(); string strId=dataGridView1.Rows[dataGridView1.CurrentRow.Index ...
- HDU 4180 扩展欧几里得
RealPhobia Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 【HDU 2087 剪花布条】
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...