CF1209H Moving Walkways 题解
MyukiyoMekya · · 题解
先把没有传送带的段设为速度为
考虑从左往右不断加入传送带,假设加入传送带速度为
先把速度拉到顶 (
考虑把让前面的某一个长度为
设
稍微推一下发现
那这样就好办了,拿个 std::map 维护一下,不断取
注意每个传送带能节省的能量是有上限的,以及处理当前传送带之前要把当前传送带也考虑进去,因为可能不够拿或者不优。
时间复杂度
// Fresh Peach Heart Shower
#include <bits/stdc++.h>
const double eps=1e-10;
std::map<double ,double > f;
double ans;
inline void insert(double d,double v)
{
double rem=d/(v+1);
ans+=rem;
f[v]+=rem+(v>1?d/(v-1):0);
while(rem>eps)
{
double x=f.rbegin()->first,sub=std::min(f[x],rem);
f[x]-=sub,rem-=sub,ans+=sub/x;
if(f[x]<eps)f.erase(x);
}
}
signed main(void)
{
std::ios::sync_with_stdio(0),std::cin.tie(0);
int n,L;std::cin>>n>>L;
double x,y,z,lst=0;
while(n--)std::cin>>x>>y>>z,insert(x-lst,1),insert(y-x,z+1),lst=y;
insert(L-lst,1);
std::printf("%.15lf\n",ans);
return 0;
}