BZOJ3795 : 魏总刷DP
对于HARD:
需要满足$k+u[i]\times k\leq T+late[i]$。
对于EASY:
需要满足$k+u[i]\times k\leq T-rest[i]$。
故对于HARD,设$a[i]=-late[i]$,对于EASY,设$a[i]=rest[i]$,并将所有题目的$u[i]$都$+1$。
那么需要满足$\max(u[i]\times k+a[i])\leq T$。
求出这些直线形成的下凸壳,分段积分即可。
时间复杂度$O(n\log n)$。
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100010;
const double eps=1e-9;
int n,i,x,q[N],t;char ch[9];double m,L,R,f[N],ans;
struct P{int k,b;}a[N];
inline bool cmp(const P&a,const P&b){return a.k==b.k?a.b>b.b:a.k<b.k;}
inline double pos(int x,int y){return 1.0*(a[x].b-a[y].b)/(a[y].k-a[x].k);}
inline int sgn(double x){
if(x>eps)return 1;
if(x<-eps)return -1;
return 0;
}
inline void cal(double l,double r,int k,int b){
l=max(l,0.0),r=min(r,min(m,(R-b)/k));
if(l+eps>r)return;
double mid=min(max((L-b)/k,l),r);
ans+=(mid-l)*(R-L)+(R-b)*(r-mid)-(r*r-mid*mid)*k/2;
}
int main(){
scanf("%d%lf%lf%lf",&n,&m,&L,&R);
for(i=1;i<=n;i++)scanf("%d",&a[i].k),a[i].k++;
for(i=1;i<=n;i++){
scanf("%s%d",ch,&x);
if(ch[0]=='H')a[i].b=-x;else a[i].b=x;
}
sort(a+1,a+n+1,cmp);
for(q[t=1]=1,i=2;i<=n;i++)if(a[i].k>a[i-1].k){
while(t>1&&sgn(pos(q[t-1],q[t])-pos(q[t],i))>=0)t--;
q[++t]=i;
}
for(f[t]=m,i=1;i<t;i++)f[i]=pos(q[i],q[i+1]);
for(i=1;i<=t;i++)cal(f[i-1],f[i],a[q[i]].k,a[q[i]].b);
return printf("%.4f",ans/m/(R-L)),0;
}
BZOJ3795 : 魏总刷DP的更多相关文章
- bzoj 3795: 魏总刷DP
Description 魏总,也就是DP魏又开始刷DP了.一共有n道题,第i道题魏总原本需要u[i]秒的时间.不过,为了表达对这些水题的藐视,魏总决定先睡k秒再开始刷题.魏总并不清楚自己会睡多久,只知 ...
- 怒刷DP之 HDU 1257
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- 怒刷DP之 HDU 1160
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- 怒刷DP之 HDU 1260
Tickets Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- 怒刷DP之 HDU 1176
免费馅饼 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- 怒刷DP之 HDU 1087
Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64 ...
- 怒刷DP之 HDU 1114
Piggy-Bank Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit S ...
- 怒刷DP之 HDU 1069
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- 怒刷DP之 HDU 1024
Max Sum Plus Plus Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- WBXML 1.3协议摘要
协议地址:WAP195 网络字节顺序:big-endian. 为什么要加0x40? 参考:Compressing XML When an element contains content (t ...
- java用swing画可以行走的乌龟
代码如下: import java.awt.Color;import java.awt.Graphics;import java.awt.event.KeyEvent;import java.awt. ...
- js调试console.log使用总结图解
一 实例 打印字符串和对象: 可展开对象查看内部情况: 看一下console对象本身的定义情况: 输出对象情况: utag对象所在文件: 输出对象: 二 Console.log 总结 1 如果你j ...
- error: <item> inner element must either be a resource reference or empty.
FAQ: Android resource compilation failedOutput: /home/cmm/code/AndroidHttpCapture/app/build/intermed ...
- 磁盘blk_update_request: I/O error
https://www.cnblogs.com/chris-cp/p/6340289.html
- github的pull request是指什么意思
有一个仓库,叫Repo A.你如果要往里贡献代码,首先要Fork这个Repo,于是在你的Github账号下有了一个Repo A2,.然后你在这个A2下工作,Commit,push等.然后你希望原始仓库 ...
- Loadrunner和JMeter并发对比
今天在项目中测试发现,其实LR才是实际意义上的并发测试,JMeter不算并发 记录用户登录日志: LR脚本: 1.登录操作放在init初始化中,用5个虚拟用户并发测试:
- Codeforces 915G Coprime Arrays 莫比乌斯反演 (看题解)
Coprime Arrays 啊,我感觉我更本不会莫比乌斯啊啊啊, 感觉每次都学不会, 我好菜啊. #include<bits/stdc++.h> #define LL long long ...
- crc循环冗余检验
CRC(Cyclic Redundancy Check):循环冗余检验.在链路层被广泛使用的检错技术. CRC原理: 1.发送端 1.1.在发送端先将数据分组,每组k个数据.假定要传送的数据是M. 1 ...
- 记Ubuntu Mongodb 和 Mysql的安装与使用
安装mongodb 参考链接 https://www.cnblogs.com/shileima/p/7823434.html https://blog.csdn.net/xlengji/article ...