hdu-3276-dp+二分+单调队列
Star
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 516 Accepted Submission(s): 213
One day, Resty comes to the Moon to have his picnic. Soon he found that he can see so many beautiful stars here! You can never find such a view again - All the beautiful stars are in one line!! So Resty wants to take photos to record the incredible moment.
Resty likes those stars so much so he knows which one is more beautiful. Now he gives each star a score, (a number between 1 and 200000, the higher, the better). So we can use an integer sequence to show the stars from left to right.
Resty's camera is very strange and it will take two photos at one time, and each photo will contain a series of continuous stars in it. No stars will appear in both photos, and even no two stars that adjacent to each other will be in different photos. The number of stars in each photo will between x and y.
Now, Resty tells you the sequence, you must find two photos that the average score of all the stars in the photos is as great as possible.
Process to the END OF DATA.
For each test case:
The first line contains 3 integers: n, x, y. n is the number of stars.
1 <= x < y <= n <=50000
The second line contains n integers (between 1 and 200000), the score of each stars.
Output Format is "Case ID: ANS" one line for each data
Don't print any empty line to the output
1 2 3 4 5
6 2 3
6 1 2 4 3 5
Case 2: 3.800
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define eps 1e-6
int a[];
double b[],fl[],fr[];
int n,x,y;
struct node{
int id;
double s;
bool operator< (const node& tmp)const{
return s>tmp.s;
}
};
bool ok(double p){
for(int i=;i<=n;++i){
b[i]=b[i-]+(double)a[i]-p;
}
b[n+]=b[n];
priority_queue<node>q;
fl[]=-inf;
fr[n+]=-inf; for(int i=;i<=n;++i){
if(i-x>=) q.push(node{i-x,b[i-x]});
fl[i]=fl[i-];
while(!q.empty() && i-q.top().id>y) q.pop();
if(!q.empty()){
fl[i]=max(fl[i],b[i]-b[q.top().id]);
}
}
while(!q.empty())q.pop();
for(int i=n;i>=;--i){
if(i+x<=n+) q.push(node{i+x,b[n]-b[i+x-]});
fr[i]=fr[i+];
while(!q.empty() && q.top().id-i>y) q.pop();
if(!q.empty()){
fr[i]=max(fr[i],b[n]-b[i-]-q.top().s);
}
//cout<<"fr="<<fr[i]<<endl;
}
double res=-inf;
for(int i=;i<=n;++i){
res=max(res,fl[i-]+fr[i+]);
}
return res>=;
}
int main(){
int i,j,k,cas=;
while(cin>>n>>x>>y){
for(i=;i<=n;++i) scanf("%d",a+i);
double l=,r=;
while(fabs(l-r)>eps){
double mid=(l+r)/;
if(ok(mid)) l=mid;
else r=mid;
}
printf("Case %d: %.3f\n",++cas,l);
}
return ;
}
hdu-3276-dp+二分+单调队列的更多相关文章
- 两种解法-树形dp+二分+单调队列(或RMQ)-hdu-4123-Bob’s Race
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4123 题目大意: 给一棵树,n个节点,每条边有个权值,从每个点i出发有个不经过自己走过的点的最远距离 ...
- [P1020]导弹拦截 (贪心/DP/二分/单调队列)
一道很经典的题 这道题就是要求一个最长单调不升子序列和一个最长单调上升子序列. 先打了一个n2复杂度的 用DP #include<bits/stdc++.h> using namespac ...
- [BZOJ1044][HAOI2008]木棍分割 二分 + 单调队列优化dp + 滚动数组优化dp
Description 有n根木棍, 第i根木棍的长度为Li,n根木棍依次连结了一起, 总共有n-1个连接处. 现在允许你最多砍断m个连接处, 砍完后n根木棍被分成了很多段,要求满足总长度最大的一段长 ...
- NYOJ-258/POJ-2559/HDU-1506 Largest Rectangle in a Histogram,最大长方形,dp或者单调队列!
Largest Rectangle in a Histogram 这么经典的题硬是等今天碰到了原题现场懵逼两小时才会去补题.. ...
- NOIP模拟 最佳序列 - 二分 + 单调队列
题意: 各一个n(\(\le 20000\))的序列,定义纯洁序列为长度len满足\(L \le len \le R\)的序列,纯洁值为某一纯洁序列的平局值,输出所有纯洁序列中最大平均值. 分析: 二 ...
- [USACO12MAR]花盆 二分 单调队列
[USACO12MAR]花盆 二分 单调队列 存在一个长度为\(x\)的区间\([l,r]\),使得区间中最大值与最小值差至少为\(w\),求这个最小的\(x\) \(n\le 100000\),\( ...
- 【HDU 3401 Trade】 单调队列优化dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3401 题目大意:现在要你去炒股,给你每天的开盘价值,每股买入价值为ap,卖出价值为bp,每天最多买as ...
- 2018.09.26洛谷P3957 跳房子(二分+单调队列优化dp)
传送门 表示去年考普及组的时候失了智,现在看来并不是很难啊. 直接二分答案然后单调队列优化dp检验就行了. 注意入队和出队的条件. 代码: #include<bits/stdc++.h> ...
- 洛谷P3975 跳房子 [DP,单调队列优化,二分答案]
题目传送门 跳房子 题目描述 跳房子,也叫跳飞机,是一种世界性的儿童游戏,也是中国民间传统的体育游戏之一. 跳房子的游戏规则如下: 在地面上确定一个起点,然后在起点右侧画 n 个格子,这些格子都在同一 ...
- 【BZOJ2806】[Ctsc2012]Cheat 广义后缀自动机+二分+单调队列优化DP
[BZOJ2806][Ctsc2012]Cheat Description Input 第一行两个整数N,M表示待检查的作文数量,和小强的标准作文库的行数接下来M行的01串,表示标准作文库接下来N行的 ...
随机推荐
- 基于GIT的管理
常用命令 git init : 初始化仓库git add 文件名 :把文件添加到暂存区git commit -m "操作记录" : 提交到仓库,设置相关操作的记录 git stat ...
- mysql 触发器 trigger用法 three (稍微复杂的)
MySQL包含对触发器的支持.触发器是一种与表操作有关的数据库对象,当触发器所在表上出现指定事件时,将调用该对象,即表的操作事件触发表上的触发器的执行. 创建触发器 在MySQL中,创建触发器语法如下 ...
- bzoj1658: [Usaco2006 Mar]Water Slides 滑水
Description It's a hot summer day, and Farmer John is letting Betsy go to the water park where she i ...
- bzoj1643 / P2666 [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪
[Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪 简单的dfs题 枚举前3个完全平方数,判断最后一个是不是完全平方数,统计合法方案数即可. (zz选手竟把数 ...
- Linux系统安装telnet以及xinetd服务
Linux系统安装telnet以及xinetd服务 一.安装telnet 1.检测telnet-server的rpm包是否安装 # rpm -qa telnet-server 若无输入内容,则表示没有 ...
- mysql 批处理文件出错后继续执行
在升级批处理sql脚本的时候,由于各种编写的不规范.不可重复执行,我们通常希望在sql脚本出错后不中止,而是执行完成.虽然这些问题可通过编写可重复执行的mysql存储过程比如add_column/dr ...
- centos6.7rsync端与window2012服务器实时文件同步
windows文件共享我就不截图了,估计大家都会,我就直接在centos6.7上操作了一.挂载win共享文件夹mount -t cifs -o username=administrator,passw ...
- USACO 1.3 Wormholes - 搜索
Wormholes Farmer John's hobby of conducting high-energy physics experiments on weekends has backfire ...
- AndroidStudio V2.0.0.汉化
汉化包下载:http://pan.baidu.com/s/1kVKYUjH AndroidStudio V2.0.x.版汉化工作介绍 resource_en.jar------> resourc ...
- Qt Designer中文入门教程
Qt Designer窗口布局Layouts提供了四种布局方法,他们是: Vertical Layout 纵向布局Horizontal Layout 横向布局Grid Layout 栅格布局Form ...