Vacation
题意:
n 辆车排队过路口,每辆车给定最大车速、车长、车头到路口的距离,求最后一辆车的最短通过时间
分析:
确定每辆车通过路口需要的总路程 sum[i], 然后分情况讨论:
- 前车速度小于后车速度,后车只能以前车速度运行,这样就会导致前后车花费相同时间到达
- 前车速度大于后车速度,都以自己的速度运行
统计一遍每辆车到达的最大时间,答案取 max
实现:
#include <bits/stdc++.h>
using namespace std;
#define mst(x, y) memset(x, y, sizeof x)
#define endl '\n'
#define INF LONG_LONG_MAX
#define pb push_back
#define x first
#define y second
#define int long long
#define Lson u << 1, l, mid
#define Rson u << 1 | 1, mid + 1, r
#define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const int N = 2000010, MOD = 1e9 + 7;
const double EPS = 1e-6;
typedef pair<int, int> PII;
typedef unordered_map<int, int> Ump;
int T;
int n;
double l[N], s[N], v[N];
int sum[N];
void solve()
{
for (int i = 0; i <= n; i++)
scanf("%lf", &l[i]);
for (int i = 0; i <= n; i++)
scanf("%lf", &s[i]);
for (int i = 0; i <= n; i++)
scanf("%lf", &v[i]);
sum[0] = s[0];
for (int i = 1; i <= n; i++)
sum[i] = sum[i - 1] - s[i - 1] + s[i] + l[i];
double res = 0;
for (int i = 0; i <= n; i++)
res = max(res, sum[i] * 1.0 / v[i]);
printf("%.10lf\n", res);
}
signed main()
{
while (~scanf("%lld", &n))
solve();
return 0;
}
标签:每辆车,int,路口,Vacation,2019,速度,校赛,define
From: https://www.cnblogs.com/Aidan347/p/17241102.html