注意看此代码
#include<bits/stdc++.h>
using namespace std;
struct node{
int x,y,s;
};
bool check(double maxn, const vector<node>& a) {
double time = 0.0;
for (int i = 0; i < a.size(); i++) {
const auto& st = a[i];
double depart_time = max(time, (i == 0 ? 0.0 : (double)a[i-1].x));
double min_v = st.s / (st.y - depart_time);
if (min_v > maxn) {
return false;
}
double t_i = depart_time + st.s / maxn;
if (t_i < st.x) {
t_i = st.x;
}
if (t_i > st.y) {
return false;
}
time = t_i;
}
return true;
}
double erfen(const vector<node>& a) {
double left = 0.0;
double right = 1e18;
for (int iter = 0; iter < 100; ++iter) {
double mid = (left + right) / 2;
if (check(mid, a)) {
right = mid;
} else {
left = mid;
}
}
return right;
}
int main(){
int n;
cin>>n;
vector<node> a(n);
for(int i=0;i<n;i++){
cin>>a[i].x>>a[i].y>>a[i].s;
}
double ans=erfen(a);
printf("%.2lf",ans);
return 0;
}
/*
3
1 2 2
6 6 2
7 8 4
*/