版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_39972971/article/details/88657750
【题目链接】
【思路要点】
- 将每一辆公交车的出发站,出发时间、目标站,到达时间视为关键点,按照时间从大到小 即可。
- 时间复杂度 。
【代码】
#include<bits/stdc++.h> using namespace std; const int MAXN = 2e6 + 5; typedef long long ll; typedef long double ld; typedef unsigned long long ull; template <typename T> void chkmax(T &x, T y) {x = max(x, y); } template <typename T> void chkmin(T &x, T y) {x = min(x, y); } template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } template <typename T> void write(T x) { if (x < 0) x = -x, putchar('-'); if (x > 9) write(x / 10); putchar(x % 10 + '0'); } template <typename T> void writeln(T x) { write(x); puts(""); } int n, m, tot, pos[MAXN]; ll k; map <pair <ll, int>, int> home; pair <ll, int> x[MAXN], y[MAXN]; double ans[MAXN], dp[MAXN], p[MAXN]; vector <pair <int, double> > a[MAXN]; int main() { read(m), read(n), read(k); static set <pair <ll, int>> st; for (int i = 1; i <= m; i++) { read(x[i].second), read(y[i].second); read(x[i].first), read(y[i].first), y[i].first++; st.insert(x[i]), st.insert(y[i]); scanf("%lf", &p[i]); } for (auto x : st) { pos[++tot] = x.second; home[x] = tot; } for (int i = 1; i <= m; i++) a[home[x[i]]].emplace_back(home[y[i]], p[i]); ans[1] = 1; for (int i = tot; i >= 1; i--) { dp[i] = ans[pos[i]]; for (auto x : a[i]) chkmax(dp[i], ans[pos[i]] * (1 - x.second) + dp[x.first] * x.second); ans[pos[i]] = dp[i]; } printf("%.10lf\n", ans[0]); return 0; }