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

题目链接

传送门

题意

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

思路

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

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

代码实现如下

#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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值