洛谷 P1542 包裹快递

题目传送门

解题思路:

二分答案,按照题目要求模拟验证,但数据太毒,要用long double.

AC代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 
 4 using namespace std;
 5 
 6 long double l,r = 1e9,mid,ans;
 7 int n;
 8 struct kkk {
 9     long double x,y,z;
10 }e[200001];
11 
12 inline bool check(long double len) {
13     long double now = 0;
14     for(int i = 1;i <= n; i++) {
15         now += e[i].z / len;
16         if(now > e[i].y) return false;
17         if(now < e[i].x) now = e[i].x;    
18     }
19     return true;
20 }
21 
22 int main() {
23     scanf("%d",&n);
24     for(int i = 1;i <= n; i++) 
25         scanf("%Lf%Lf%Lf",&e[i].x,&e[i].y,&e[i].z);
26     while(r - l >= 0.0001) {
27         mid = (l + r) / 2;
28         if(check(mid))
29             r = mid,ans = mid;
30         else
31             l = mid;
32     }
33     printf("%.2Lf",ans);
34     return 0;
35 } 

 

猜你喜欢

转载自www.cnblogs.com/lipeiyi520/p/11780100.html