文章
1
粉丝
181
获赞
0
访问
5.2k
#include<cstdio>
#include<algorithm>
using namespace std;
const int INF =1000000000;
struct Station{
double p, dis;//单位油价,距起点距离
}sta[510];
bool cmp(Station a, Station b){
return a.dis < b.dis;
}
int main(){
double Cmax, D, Davg;
int n;
while(scanf("%lf%lf%lf%d", &Cmax, &D, &Davg, &n)!= EOF){
for(int i = 0; i < n; i++){
scanf("%lf %lf", &sta[i].p, &sta[i].dis);
}
sta[n].p = 0; //终点价格为0
sta[n].dis = D;//终点距离为D
sort(sta, sta +n, cmp); //将加油站按从近到远排序
if(sta[0].dis != 0){//起点没有加油站
printf("The maximum travel distance = 0.00\n");
} else{
int now = 0; //当前加油站编号
//记录总花费,现在油量,加满油能走距离
double ans = 0, nowTank = 0, MAX = Cmax * Davg;
while(now < n){//每次循环选出下一个到达的加油站
//选出最远距离中第一个油价低于当前油价的加油站
int k = -1; //最低油站编号
double priceMin = INF; //最低油价
for(int i = now + 1; i <= n && sta[i].dis - sta[now].dis <= MAX; i++){
if(sta[i].p < priceMin)...
登录后发布评论
暂无评论,来抢沙发