• 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{sumlimits_{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("*********
    ")
    #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
    ", ans);
        }
        return 0;
    }
    
  • 相关阅读:
    mysql应用技巧
    Python httplib学习
    桌标相关知识
    行业百科知识--Github
    Ghost win7 系统安装(虚拟机)
    记一次pycharm和vscode因网络问题插件下载失败的问题
    Pydiction补全插件
    MS17-010远程溢出漏洞(CVE-2017-0143)
    shell快速入门
    Yarn架构
  • 原文地址:https://www.cnblogs.com/Dillonh/p/11229894.html
Copyright © 2020-2023  润新知