2019年杭电多校第一场 1004题Vacation(HDU6581+数学)

题目链接

传送门

题意

\(n+1\)辆车要过红绿灯,告诉你车的长度、与红绿灯的起点(题目假设红绿灯始终为绿)、车的最大速度,问你第\(0\)辆车(距离最远)车头到达红绿灯起点的时间是多少(每辆车最多和前面的车无缝衔接)。

思路

比赛的时候没啥思路,后来仔细一想,其实对于第\(0\)辆车的最终状态只有两种状态:

  • 前面的车都不影响它的时间(也就是一直都不会与前面的车衔接),此时时间为\(\frac{s_0}{v_0}\)
  • 与前面的车无缝衔接,那么由于第\(0\)辆车的车头会在数轴\(0\)这个点(也就是红绿灯起点,车的位置为正,另一边为负),那么第\(1\)辆车就会在\(-l_1\)处,第\(2\)辆在\(-l_1-l_2\)\(\dots\)此时时间为\(max(\frac{\sum\limits_{j=1}^{i}l_j+s_i}{v_i})\)

代码实现如下

#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;

typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;

#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("/home/dillonh/CLionProjects/Dillonh/in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)

const double eps = 1e-8;
const int mod = 1000000007;
const int maxn = 100000 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;

int n;
int l[maxn], s[maxn], v[maxn];

int main() {
#ifndef ONLINE_JUDGE
    FIN;
#endif
    while(~scanf("%d", &n)) {
        for(int i = 0; i <= n; ++i) {
            scanf("%d", &l[i]);
        }
        for(int i = 0; i <= n; ++i) {
            scanf("%d", &s[i]);
        }
        for(int i = 0; i <= n; ++i) {
            scanf("%d", &v[i]);
        }
        LL las = -l[0];
        double ans = 0.0;
        for(int i = 0; i <= n; ++i) {
            las += l[i];
            ans = max(ans, 1.0 * (las + s[i]) / v[i]);
        }
        printf("%.7f\n", ans);
    }
    return 0;
}
posted @ 2019-07-23 09:48  Dillonh  阅读(463)  评论(0编辑  收藏  举报