'commit'
This commit is contained in:
55
TangDou/CSP-J/MKX_B/3241.cpp
Normal file
55
TangDou/CSP-J/MKX_B/3241.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define int long long
|
||||
const int N = 100010;
|
||||
|
||||
int v[N]; // 站点间的距离
|
||||
int a[N]; // 每个站点的油价
|
||||
int n; // n个站点
|
||||
double d; // 1升油可以跑多少公里
|
||||
int money; // 一共花费
|
||||
int r; // 油箱的油可以跑的公里数
|
||||
/*
|
||||
5 4
|
||||
10 10 10 10
|
||||
9 8 9 6 5
|
||||
|
||||
答案:79
|
||||
|
||||
*/
|
||||
int getMoney(int begin, int end) { // 左闭右开
|
||||
int length = 0;
|
||||
for (int i = begin; i < end; i++) length += v[i];
|
||||
|
||||
if (r >= length) {
|
||||
// 不用加油
|
||||
r -= length;
|
||||
return 0;
|
||||
} else {
|
||||
// 需要加油, 计算加多少油: 油箱的油还有剩余,还能跑几公里
|
||||
int add = ceil((length - r) / d);
|
||||
// 计算加油费用
|
||||
int x = a[begin] * add;
|
||||
// 跑到 end, 油箱的油还能跑几公里
|
||||
r = add * d + r - length;
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
signed main() {
|
||||
freopen("road.in","r", stdin);
|
||||
freopen("road.out", "w", stdout);
|
||||
cin >> n >> d; // n个站点,每升油可以让车前进d公里
|
||||
for (int i = 1; i < n; i++) cin >> v[i]; // 站点间的距离 a1~a2,a2~a3,...
|
||||
for (int i = 1; i <= n; i++) cin >> a[i]; // 不同站点加油的价格
|
||||
|
||||
int i = 1;
|
||||
while (i < n) {
|
||||
int j = i + 1;
|
||||
// 找到下一个便宜的加油站
|
||||
while (j <= n && a[j] >= a[i]) j++;
|
||||
money += getMoney(i, j);
|
||||
i = j;
|
||||
}
|
||||
cout << money << endl;
|
||||
}
|
||||
Reference in New Issue
Block a user