其他分享
首页 > 其他分享> > 2019年杭电多校 1004题Vacation(HDU6581+数学)

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

作者:互联网

题目链接

传送门

题意

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

思路

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

代码实现如下

#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;
}

标签:杭电多校,typedef,HDU6581,红绿灯,Vacation,long,辆车,pair,include
来源: https://www.cnblogs.com/Dillonh/p/11229894.html