标签:int 窗口 lan 思路 targe line log target ace
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 5e5 + 5;
const db eps = 1e-8;
ll L;
int a, b, t, r, n;
int pre[maxn];
ll dis[maxn];
db dp[maxn];
db val[maxn];
int dcmp(db x) {
if (fabs(x) < eps) return 0;
return x > 0 ? 1 : -1;
}
void print(int i, int cnt) {
if (!i) {
cout << cnt << '\n';
return;
}
print(pre[i], cnt + 1);
cout << i - 1 << " ";
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> L >> a >> b >> t >> r >> n;
for (int i = 1; i <= n; i++) {
cin >> dis[i];
}
dis[++n] = L;
ll lim0 = t * a + r * b;
ll lim1 = t * a;
int j = 1, k = 1;
db rej = 1e18;
int idj = 0;
int Q[maxn], head = 1, tail = 0;
for (int i = 1; i <= n; i++) {
dp[i] = (db)dis[i] / a;
while (j < i && dis[i] - dis[j] >= lim0) {
db tmp = dp[j] - (db)dis[j] / a;
if (dcmp(tmp - rej) < 0) {
rej = tmp;
idj = j;
}
j++;
}
if (idj) {
db tmp = rej + (db)(dis[i] - lim0) / a + t + r;
if (dcmp(dp[i] - tmp) > 0) {
dp[i] = tmp;
pre[i] = idj;
}
}
while (k < i && dis[i] - dis[k] >= lim1) {
val[k] = dp[k] - (db)dis[k] / b;
while (head <= tail && dcmp(val[Q[tail]] - val[k]) > 0) tail--;
Q[++tail] = k++;
}
while (head <= tail && dis[i] - dis[Q[head]] >= lim0) head++;
if (head <= tail) {
db tmp = val[Q[head]] + (db)(dis[i] - lim1) / b + t;
if (dcmp(dp[i] - tmp) > 0) {
dp[i] = tmp;
pre[i] = Q[head];
}
}
}
print(pre[n], 0);
}
标签:int 窗口 lan 思路 targe line log target ace
原文地址:https://www.cnblogs.com/AlphaWA/p/10917784.html