原题链接:

http://acm.hdu.edu.cn/showproblem.php?pid=6581

Vacation
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Special Judge

Problem Description
Tom and Jerry are going on a vacation. They are now driving on a one-way road and several cars are in front of them. To be more specific, there are n cars in front of them. The ith car has a length of li, the head of it is si from the stop-line, and its maximum velocity is vi. The car Tom and Jerry are driving is l0 in length, and s0 from the stop-line, with a maximum velocity of v0.
The traffic light has a very long cycle. You can assume that it is always green light. However, since the road is too narrow, no car can get ahead of other cars. Even if your speed can be greater than the car in front of you, you still can only drive at the same speed as the anterior car. But when not affected by the car ahead, the driver will drive at the maximum speed. You can assume that every driver here is very good at driving, so that the distance of adjacent cars can be kept to be 0.
Though Tom and Jerry know that they can pass the stop-line during green light, they still want to know the minimum time they need to pass the stop-line. We say a car passes the stop-line once the head of the car passes it.
Please notice that even after a car passes the stop-line, it still runs on the road, and cannot be overtaken.

Input
This problem contains multiple test cases.
For each test case, the first line contains an integer n (1≤n≤105,∑n≤2×106), the number of cars.
The next three lines each contains n+1 integers, li,si,vi (1≤si,vi,li≤109). It's guaranteed that si≥si+1+li+1,∀i∈[0,n−1]

Output
For each test case, output one line containing the answer. Your answer will be accepted if its absolute or relative error does not exceed 10−6.
Formally, let your answer be a, and the jury's answer is b. Your answer is considered correct if |a−b|max(1,|b|)≤10−6.
The answer is guaranteed to exist.

Sample Input
1
2 2
7 1
2 1
2
1 2 2
10 7 1
6 2 1

Sample Output
3.5000000000
5.0000000000

题意:n辆车按前后顺序在一条单行道上行驶,若后一辆车碰到了前一辆车的尾巴,也必须按前一辆车的速度行驶,不能超越,按离终点距离从大到小的顺序给你n+1辆车的车身长,车头离终点距离,和各自的速度(你是离终点最远的那一辆车),问你冲过终点的最短时间。

思路:这道题我们不应该把重点放在每一辆车何时冲过终点,不然这题会变得非常复杂,而是应该考虑冲过终点后它何时能留出足够的空间让后面的车放下,这才是我们真正应该求的临界状态,比如第一辆车长度是3,后面一辆长度是2,则第一辆车至少要车头冲过终点线并且再走5的长度才能让后面一辆车放下(它自己的车身3+后面那辆车的长度2),说的明白点,就是至少要再跑除了我们自己那辆车之外的所有车的长度(因为我们自己的车只要冲过终点就行了,所以前面的车不需要给我们的车留空间),这样就能让后面的车全部都跑出来,这样我们的车才能冲过终点。要是冲过那个临界位置我们就不用管了呀,所以我们只要考虑临界位置就好了。那么问题又来了,要是后面的车被前面的车堵住了怎么办?我们可以先思考一下,什么情况下后面一辆车会被前面一辆车给堵住?当然是后面一辆车到达它自己应该到的那个位置时,前面一辆车却没有到达前面一辆车它自己应该到达的位置(也就是各自的临界位置),这样他们肯定在行驶过程中相碰了。所以真正用的时间就是最慢到达自己临界位置的那辆车所用的时间(因为后面的车全部被这辆“拖拉机”堵住了),如此类推下去,我们需要的时间就是每一辆车达到它应该到达的位置的时间的最大值,此题结束。

代码:

 #include "stdio.h"
#include "algorithm"
using namespace std;
const int N=1e5+;
int n,l[N],s[N],v[N],sum[N];
double t,t1; int main() {
while(~scanf("%d", &n))
{
t=-; ///初始化一下答案
for (int i = ; i <= n + ; i++)
scanf("%d", &l[i]);
for (int i = ; i <= n + ; i++)
scanf("%d", &s[i]);
for (int i = ; i <= n + ; i++)
scanf("%d", &v[i]);
for(int i=;i<=n+;i++)
sum[i]=sum[i-]+l[i]; ///先把车身长度也就是每辆车需要预留的位置给预处理出来
for(int i=n+;i>=;i--)
{
t1=(s[i]+sum[i])*1.0/v[i]; ///这辆车到达它应该到达的位置的位置所用的时间
t=max(t,t1); ///找出那辆最慢的“拖拉机”,当i=1时,t代表我们没有被挡直接冲过终点所用的时间
}
printf("%.10f\n",t);
}
return ;
}

谢谢访问,如果觉得好的话可以点个赞哦,有不懂的也可以在下面提问,互相学习,共同进步,谢谢大家的支持!

hdu 6581 Vacation【思维】的更多相关文章

  1. HDU 6581 Vacation

    Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission( ...

  2. 【HDU - 6581】Vacation(思维)

    Vacation 题意 有n+1辆车,属性有长度l,距离终点的距离s,速度v问你最末尾的车到达终点的时间 Sample Input 1 2 2 7 1 2 1 2 1 2 2 10 7 1 6 2 1 ...

  3. hdu 6851 Vacation(思维+贪心)

    传送门 •题意 有编号0到n,n+1辆车排队过红绿灯,从0到n离交通灯线越来越近 每辆车都有一个最大速度v,车身长度l,和离交通灯线的距离s, 一辆车头到达线则说明这辆车已到达线 如果一辆车前面没有紧 ...

  4. HDU 5776 sum (思维题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5776 题目让你求是否有区间的和是m的倍数. 预处理前缀和,一旦有两个数模m的值相同,说明中间一部分连续 ...

  5. hdu 4803 贪心/思维题

    http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么?  G++  AC  C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...

  6. Binary Tree HDU - 5573 (思维)

    题目链接: B - Binary Tree  HDU - 5573 题目大意: 给定一颗二叉树,根结点权值为1,左孩子权值是父节点的两倍,右孩子是两倍+1: 给定 n 和 k,让你找一条从根结点走到第 ...

  7. HDU 5178 pairs —— 思维 + 二分

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5178 pairs Time Limit: 2000/1000 MS (Java/Others)     ...

  8. ACM-ICPC 2016 大连赛区现场赛 K. Guess the number && HDU 5981(思维+DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5981 题意:A在[L, R]之间随机选取一个数X,之后B来猜这个数,如果猜的数比X小,那么A就告诉B猜 ...

  9. ACM-ICPC 2017 沈阳赛区现场赛 M. Wandering Robots && HDU 6229(思维+期望)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6229 参考题解:https://blog.csdn.net/lifelikes/article/det ...

随机推荐

  1. 一个小证明(题解 P5425 Part1)

    所以这道题为什么可以这样做 嗯,我也不知道,不过我是来填坑的. \(Q\):为什么要把牛分成\(1\),\(1\)......\(N-K+1\)这样的\(K\)组呢? \(A\):我们设第\(i\)组 ...

  2. bzoj 4754: [Jsoi2016]独特的树叶

    不得不说这是神题. %%%   http://blog.csdn.net/samjia2000/article/details/51762811 #include <cstdio> #in ...

  3. R 《回归分析与线性统计模型》page121,4.4

    rm(list = ls()) A = read.xlsx("xiti_4.xlsx",sheet = 4) names(A) = c("ord"," ...

  4. navicat报错2005 - Unknown MySQL server host 'localhost' (0) 原因及解决方法

    报错原因:没有连接互联网,用navicat连接本地mysql数据库,连接属性ip为localhost. 解决办法:将ip改为127.0.0.1即可.localhost是需要DNS解析后才会是127.0 ...

  5. ASP.NETCore -----导出Excel文件并下载

    本事例分为nopi(安装DotNetCore.NPOI)下载和EPPlus(EPPlus.Core.dll)下载,其中npoi下载演示的是根据执行的模板进行数据下载 npoi帮助类NpoiExcelU ...

  6. Tips for traing DNN

    1.   一般的机器学习方法不会在train好的模型上检查training data的结果,因为DNN在training data上都没有办法获得很好的正确率, 所以要先回头看一下要对模型做什么修改, ...

  7. 本地Redis服务配置

    本地Redis服务配置 要求:在虚拟机中启动redis服务,并要在windows物理机上取得链接 虚拟机安装略,(结果如下) windows工作机上装了Oracle VM VirtualBox,并在其 ...

  8. (HN)AHOI2018 转盘

    题意: 有 \(n\) 个格子围成一圈,每个格子里有一个物品,每个物品的出现时间为 \(T_i\) .开始时选择一个格子为起点,每个单位时间可以向前走一格或不动,若当前格的物品已出现则将其标记.有 \ ...

  9. UVA - 11093 Just Finish it up(环形跑道)(模拟)

    题意:环形跑道上有n(n <= 100000)个加油站,编号为1~n.第i个加油站可以加油pi加仑.从加油站i开到下一站需要qi加仑汽油.你可以选择一个加油站作为起点,起始油箱为空(但可以立即加 ...

  10. mac允许“任何来源”下载的应用

    刚买的mac电脑,我们不止在App Store上下载,还会通过浏览器下载 有的时候需要下载一些破解的软件,这个时候安装会提示文件被破坏,很是头疼 不用着急,这是因为mac会判断app如果被破坏,就不允 ...