胡一个错误代码都能有75pts
忘了怎么手写deque其实是懒
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); (a) <= (c); ++(a))
#define nR(a,b,c) for(register int a = (b); (a) >= (c); --(a))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Swap(a,b) ((a) ^= (b) ^= (a) ^= (b))
//#define ON_DEBUGG
#ifdef ON_DEBUGG
#define D_e_Line printf("
----------
")
#define D_e(x) cout << (#x) << " : " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt", "r", stdin)
#else
#define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#endif
using namespace std;
struct ios{
template<typename ATP>inline ios& operator >> (ATP &x){
x = 0; int f = 1; char ch;
for(ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
while(ch >= '0' && ch <= '9') x = x * 10 + (ch ^ '0'), ch = getchar();
x *= f;
return *this;
}
}io;
template<typename ATP>inline ATP max(ATP &a, ATP &b){
return a > b ? a : b;
}
#include <deque>
struct Petrol {
double cost, volume;
};
deque<Petrol> dq;
double dis[17], price[17];
int main() {
FileOpen();
double totDis, fuelMax, dx;
int n;
scanf("%lf%lf%lf%lf%d", &totDis, &fuelMax, &dx, &price[0], &n);
R(i,1,n){
scanf("%lf%lf", &dis[i], &price[i]);
if(dis[i] - dis[i - 1] > fuelMax * dx){
printf("No Solution
");
return 0;
}
}
dis[n+1] = totDis;
double fuelNow = fuelMax;
dq.push_back((Petrol){price[0], fuelMax});
double ans = price[0] * fuelMax;
R(i,1,i + 1){
double costFuel = (dis[i] - dis[i - 1]) / dx;
while(!dq.empty() && costFuel > 0){
Petrol x = dq.front(); dq.pop_front();
if(x.volume > costFuel){
fuelNow -= costFuel;
dq.push_front((Petrol){x.cost, x.volume - costFuel});
break;
}
fuelNow -= x.volume;
costFuel -= x.volume;
}
if(i == n + 1){
while(!dq.empty()) {
ans -= dq.front().cost * dq.front().volume;
dq.pop_front();
}
break;
}
while(!dq.empty() && dq.back().cost > price[i]){
ans -= dq.back().cost * dq.back().volume;
fuelNow -= dq.back().volume;
dq.pop_back();
}
ans += (fuelMax - fuelNow) * price[i];
dq.push_back((Petrol){price[i], fuelMax - fuelNow});
fuelNow = fuelMax;
}
printf("%.2lf
", ans);
return 0;
}