ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2019-07-23 09:54:42  阅读:378  来源: 互联网

标签:杭电多校 typedef HDU6581 红绿灯 Vacation long 辆车 pair include


题目链接

传送门

题意

有\(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;
}

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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有