-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1033.cpp
74 lines (69 loc) · 1.73 KB
/
1033.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// 1033.cpp
// 算法
//
// Created by 王怡凡 on 2017/9/4.
// Copyright © 2017年 王怡凡. All rights reserved.
//
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 510;
double cmax,d,davg;
int n;
const int INF = 1000000000;
struct sta {
double dis,price;
}st[maxn];
bool cmp(sta a, sta b) {
return a.dis<b.dis;
}
int main() {
scanf("%lf%lf%lf%d",&cmax,&d,&davg,&n);
int i;
for(i=0;i<n;i++) {
scanf("%lf%lf",&st[i].price,&st[i].dis);
}
st[n].price = 0;
st[n].dis = d;
sort(st,st+n+1,cmp);
int now=0;
double need,nowTank=0,ans=0;
if(st[0].dis!=0) {
printf("The maximum travel distance = 0.00");
} else {
while(now<n) {
int k=-1, MIN = INF,dmax=cmax*davg;
for(int j=now+1;(st[j].dis-st[now].dis)<=dmax&&j<=n;j++) {
if(st[j].price<MIN) {
MIN = st[j].price;
k=j;
if(MIN<st[now].price) {
break;
}
}
}
if(k==-1) {
break;
}
need = (st[k].dis - st[now].dis)/davg;
if(MIN<st[now].price) {
if(nowTank>=need) {
nowTank -= need;
} else {
ans += (need-nowTank)*st[now].price;
nowTank = 0;
}
} else {
ans += (cmax-nowTank)*st[now].price;
nowTank = cmax - need;
}
now = k;
}
if(now!=n) {
printf("The maximum travel distance = %.2lf",st[now].dis+cmax*davg);
} else {
printf("%.2lf",ans);
}
}
}