https://www.luogu.org/problem/P1016
#include<cstdio>
using namespace std;
double d[10],a[10];
int main()
{
double d1,c,d2,p,b=0;
int n;
scanf("%lf%lf%lf%lf%d",&d1,&c,&d2,&p,&n);
double x=c*d2;
d[0]=0;
a[0]=p;
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&d[i],&a[i]);
}
for(int i=1;i<=n;i++)
{
if(d[i]-d[i-1]>x)
{
printf("No Solution\n");
return 0;
}
}
double Min=505;
double tmp=0;
int tag=0;
double ans=0;
a[0]=p;
while(d1-tmp)
{
for(int i=tag+1;d[i]-tmp<=x&&i<=n;i++)
{
if(a[i]<Min)
{
Min=a[i];
tag=i;
}//找出能到达的油费小于现在的
}
if(Min<=p)
{
ans+=((d[tag]-tmp)/d2-b)*p;
b=(d[tag]-tmp)/d2;
}
else
if(d1-tmp>x)
{
ans+=(c-b)*p;
b=c;
}
else
{
ans+=((d1-tmp)/d2-b)*p;
break;
}
b-=(d[tag]-tmp)/d2;
tmp=d[tag];
p=Min;
Min=505;
}
printf("%.2lf\n",ans);
return 0;
}
原文:https://www.cnblogs.com/ShineEternal/p/qaq.html