[codevs1046]旅行家的預算
阿新 • • 發佈:2019-02-06
瞎貪心……
記錄當前為止最便宜的加油站minx
因為每一站油量最多為C,所以在當前站沒加滿的情況下,每走到一條新路優先加單價最小的加油站
要是加滿的話,直接跳到目前的加油站
加滿了油還走不到下一站就是非法情況了……(廢話)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN = 200000 + 50;
double D,C,D2,P1;
double P[MAXN],pos [MAXN],ans;
int n,now = 0,minx = 1061109567;
double sy[MAXN];
int main(){
scanf("%lf%lf%lf%lf",&D,&C,&D2,&P1);
scanf("%d",&n);
for(int i = 1;i <= n;i ++){
scanf("%lf%lf",&pos[i],&P[i]);
sy[i] = C;
}
sy[0] = C;
P[0] = P1;
pos[n + 1 ] = D;
P[n + 1] = 1061109567;
minx = 0;
for(int i = 1;i <= n + 1;i ++){
double need = (pos[i] - pos[i - 1])/D2;
if(need > C){
printf("No Solution");
return 0;
}
if(P[minx] <= P[i - 1]){
if(need <= sy[minx]){
sy[minx] -= need;
ans += need*P [minx];
}
else{
need -= sy[minx];
ans += sy[minx]*P[minx];
minx = i - 1;
sy[minx] -= need;
ans += need*P[minx];
}
}
else{
minx = i - 1;
sy[minx] -= need;
ans += need*P[minx];
}
}
printf("%.2lf",ans);
return 0;
}