Files
python/C++专题课程/NOIP算法总结/贪心/旅行家的预算/P1016.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

63 lines
1.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include<bits/stdc++.h>
using namespace std;
double maxx,mo=0,d2,temlen=0,d1,c,p;
//temlen:油箱中在到达了下一个加油站时油箱中的剩余油量可以继续走的路程
int n;
struct add
{
double co;
double dis;
}pl[10000];//加油站结构体:dis-距离起点的距离,co:油价
int move(int now)//1.now:现在到达的加油站
{
int can=99999;
int f=pl[now].dis;
for(int i=now+1;i<=n&&pl[i].dis-f<=maxx;i++)
{
if(pl[i].co<pl[now].co)//2.
{
mo+=((pl[i].dis-f-temlen)/d2)*pl[now].co;
temlen=0;
return i;
}
if(can==99999||pl[i].co<pl[can].co)can=i;
}
if(d1-pl[now].dis<=maxx)
{
mo+=((d1-pl[now].dis-temlen)/d2)*pl[now].co;
return 9999;
}
if(can==99999)//4.
{
cout<<"No Solution";
return -1;
}
else//3.
{
mo+=c*pl[now].co;
temlen+=(maxx-pl[can].dis+f);
return can;
}
}
int cmp(add a,add b)
{
return a.dis<b.dis;
}
int main()
{
cin>>d1>>c>>d2>>p>>n;
pl[0].dis=0;
pl[0].co=p;
for(int i=1;i<=n;i++)cin>>pl[i].dis>>pl[i].co;
sort(pl,pl+n,cmp);
maxx=c*d2;
int k=0,t;
do
{
t=move(k);
k=t;
if(t==-1)return 0;
}while(t!=9999);
printf("%.2f",mo);
return 0;
}