原题链接:

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. 017、Java中使用float型

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  2. 项目上线后,遇到IE浏览器不显示大部分组件的问题

    document.addEventListener('touchmove',(evt)=>{ }) 以上是ES6 语法,箭头函数,当然在IE下是不行的啦. 所以改为:ES5语法 document ...

  3. kali linux终端快捷键设置

    kali里面是没有终端快捷键的,需要自己设置. 打开设置->设备->keyboard,拉到最下面点击加号来新建一个快捷键. 名称:打开终端 命令:gnome-terminal 快捷键:Ct ...

  4. 使用 mtd-utils 烧写Arm Linux 系统各个部分

    有关博客:<Arm-Linux 移植 mtd-utils 1.x>.<mtd-utils 的 使用> 背景: 作为一项技术储备,可用于增强系统可维护性. 要求: 要求主板以mt ...

  5. MongoDB_01

    解释:MongoDB可应对 --三高需求 High performance-对数据库高并发读写的需求 Huge Storage -对海量数据的高效率存储和访问的需求 High Scalability ...

  6. Linux系统sda变sdb的解决

    起因 我的电脑有一个128G的固态以及一个500G的机械,我将系统安装在128G固态中,于是将500G的机械(/dev/sdb)挂在在/home目录下,安装完系统后执行lsblk命令 NAME MAJ ...

  7. 获取url特定字后面的参数

    var type = getUrlParam('type') ?getUrlParam('type' ):'' ; //获取url中的参数 function getUrlParam( name) { ...

  8. idea开发springboot 的mysql数据库连接问题

    今天在家用idea进行springboot开发,前面一些坑相对避免了,但是到数据库这块总是连接不上,报错主要是: Access denied for user 'root'@'localhost' ( ...

  9. javascript 创建私有变的三个方法

    //方法一 function m() { //这是私有变量 let p = 10; //这是私有方法 function pr() { return false; } //读取或者设置 私有变量和方法 ...

  10. Python 自动登录哔哩哔哩(2captcha打码平台)

    前言 研究爬虫的各位小伙伴都知道,需要登录才能获取信息的网站,是比较难爬的,原因就是在于,现在各大网站为了反爬,都加入了图片验证码,滑动验证码之类的干扰 本篇就针对哔哩哔哩的滑动验证码进行讲解和破解 ...