题解
2023-08-25 11:32:31
发布于:广东
6阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
const int size = 5e2+10; // 我crazy了
struct T {
double p, f;
} a[size];
int N, last, in_min;
double F, C, D, P, res, now, Min, Y, Sum;
int main() {
cin>>F>>C>>D>>P>>N;
a[0].f = 0, a[0].p = P;
res = C * D, now = 0, last = 0, Min = INT_MAX;
if (!N) {
if (res < F) {
cout<<"No solution";
return 0;
} else {
cout<<fixed<<setprecision(2)<<F / D * P;
return 0;
}
}
for (int i = 1; i <= N; i++) {
cin>>a[i].f>>a[i].p;
if (a[i].f - a[i - 1].f > res) {
cout<<"No Solution";
return 0;
}
}
while (now <= F) {
for (int i = last + 1; i <= N && a[i].f - a[last].f <= res; i++) {
if (a[i].p < Min) {
Min = a[i].p;
in_min = i;
if (Min < a[last].p)
break;
}
}
double temp = (a[in_min].f - a[last].f) / D;
if (Min < a[last].p) {
if (temp <= Y) {
Y -= temp;
} else {
Sum += (temp - Y) * a[last].p;
Y = 0;
}
} else {
if (F - now <= res) {
Sum += ((F - now) / D - Y) * a[last].p;
break;
}
Sum += (C - Y) * a[last].p;
Y = C - temp;
}
Min = INT_MAX;
last = in_min;
now = a[in_min].f;
}
cout<<fixed<<setprecision(2)<<Sum;
return 0;
}
这里空空如也
有帮助,赞一个