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行的 ...
随机推荐
- java多线程----Semaphore信号量
import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util ...
- 文件和打印机共享 win7 and xp
Win7 摘自:https://www.xp510.com/article/4249.html 首先开启服务 方法:开始---所有程序---附件---运行---输入services.msc----确定 ...
- Java高并发高性能分布式框架从无到有微服务架构设计
微服务架构模式(Microservice Architect Pattern).近两年在服务的疯狂增长与云计算技术的进步,让微服务架构受到重点关注 微服务架构是一种架构模式,它提倡将单一应用程序划分成 ...
- Centos 更改系统时间
.date //查看本地 .hwclock --show //查看硬件的时间 .如果硬件的时间是对不上,那就对硬件的时间进行修改 .hwclock --set --date '2222-22-22 2 ...
- P2322 [HNOI2006]最短母串问题
P2322 [HNOI2006]最短母串问题 AC自动机+bfs 题目要求:在AC自动机建的Trie图上找到一条最短链,包含所有带结尾标记的点 因为n<12,所以我们可以用二进制保存状态:某个带 ...
- apt-get build-dep
apt-get 里面有个 build-dep参数,手册写着:build-dep causes apt-get to install/remove packages in an attempt to s ...
- 'telnet'不是内部或外部命令,怎么办?
['telnet'不是内部或外部命令,也不是可运行的程序或批处理文件]当你想用telnet命令时,发现提示这句话怎么办?其实很简单,接下来为大家介绍下如何使用 1. 一般只有windows7才会出现这 ...
- POJ 2373 Dividing the Path (单调队列优化DP)题解
思路: 设dp[i]为覆盖i所用的最小数量,那么dp[i] = min(dp[k] + 1),其中i - 2b <= k <= i -2a,所以可以手动开一个单调递增的队列,队首元素就是k ...
- mysql 通过binlog 查看执行日志
环境:linux deepin15.7 mysql 5.7 1.开启binlog vim /etc/mysql/mysql.conf.d/mysqld.cnf 添加 log_bin = /var/ ...
- javascript的一些在IE下不支持的函数小结
// ============ isArray ===============// // isArray function isArray(value){ return Object.prototyp ...