跳到正文

题解

Solution of U629848 包裹快递

zhangyibin0919约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年3月25日
更新
2026年3月25日
篇幅
约 1 分钟

版本

  1. v1当前

This is the solution of U629848 包裹快递

C++
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5+1;
struct st1{
  long long l,r,s;
}a[MAXN];
int n;
bool check(long long v){
  double t=0;
  for(int i=1;i<=n;i++){
    double t0=t+(double)a[i].s/v;
    if(t0>a[i].r) return 0;
    if(t0<a[i].l) t=a[i].l;
    else t=t0;
  }
  return 1;
}
long long ff(long long l,long long r){
  long long mid=(l+r)/2;
  if(l==r) return l;
  if(check(mid)==1) return ff(l,mid);
  else return ff(mid+1,r);
}
int main(){
  cin>>n;
  a[0].s=0;
  for(int i=1;i<=n;i++){
    cin>>a[i].l>>a[i].r>>a[i].s;
    a[i].s*=1000;
  }
  cout<<fixed<<setprecision(2)<<(double)ff(1,1e11)/1000;
  return 0;
}
原文