hdu 6581 Vacation【思维】
原题链接:
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【思维】的更多相关文章
- HDU 6581 Vacation
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission( ...
- 【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 ...
- hdu 6851 Vacation(思维+贪心)
传送门 •题意 有编号0到n,n+1辆车排队过红绿灯,从0到n离交通灯线越来越近 每辆车都有一个最大速度v,车身长度l,和离交通灯线的距离s, 一辆车头到达线则说明这辆车已到达线 如果一辆车前面没有紧 ...
- HDU 5776 sum (思维题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5776 题目让你求是否有区间的和是m的倍数. 预处理前缀和,一旦有两个数模m的值相同,说明中间一部分连续 ...
- hdu 4803 贪心/思维题
http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么? G++ AC C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...
- Binary Tree HDU - 5573 (思维)
题目链接: B - Binary Tree HDU - 5573 题目大意: 给定一颗二叉树,根结点权值为1,左孩子权值是父节点的两倍,右孩子是两倍+1: 给定 n 和 k,让你找一条从根结点走到第 ...
- HDU 5178 pairs —— 思维 + 二分
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5178 pairs Time Limit: 2000/1000 MS (Java/Others) ...
- 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猜 ...
- ACM-ICPC 2017 沈阳赛区现场赛 M. Wandering Robots && HDU 6229(思维+期望)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6229 参考题解:https://blog.csdn.net/lifelikes/article/det ...
随机推荐
- PHPXhprof扩展在windows安装
1.下载在这里 http://dev.freshsite.pl/php-extensions/xhprof.html.(找不到资源可以私我我给你,这个上传不了资源) 注意:一定要找对应的php版本,t ...
- [Codeforces]1263D Secret Passwords
题目 One unknown hacker wants to get the admin's password of AtForces testing system, to get problems ...
- 主机ping虚拟机失败。虚拟机ping主机,可以ping通。
原文:https://blog.csdn.net/ww1473345713/article/details/51490525 今天打开虚拟机,然后用Xshell远程连接,发现连接不上.按照以下顺序检查 ...
- 032.SAP上用户无法打开PPE模块,查看并开通用户的PPE权限
01. 用户使用PPE模块之后,提示没有为iPPE工作台分配一个用户参数,如图所示: 02. 如果是管理员账号,则可以点击右下角的问号,来到下面界面 03.点击iPPE 用户分配者几个蓝色的字,进入下 ...
- 2 JVM 运行机制
- S7-300位逻辑指令仿真练习 停车场
第三章 S7-300 指令应用 位逻辑指令 M存储器 在PLC中M存储区(也称位存储区,又称内部存储器标志位(M)存储器区),它属于系统存储区.在你选定具体的CPU型号后,可以查看CPU的技术规格,其 ...
- UVA - 1451 Average (斜率优化)
题意:由01组成的长度为n的子串,AT由0表示,GC由1表示,求一段长度大于等于L且GC率最高的子串的起始终止坐标,若GC率相同,取长度较小,若长度相同,取起始坐标最小. 分析: 1.一个子串(i+1 ...
- pt-query-digest使用详解
1.语法及重要选项pt-query-digest [OPTIONS] [FILES] [DSN] --create-review-table 当使用--review参数把分析结果输出到表中时,如果没有 ...
- springboot#interceptor
_ 拦截器相对与过滤器Filter 而言,拦截器是spring中的概念.过滤器是servlet中的概念.在spring中肯定是优先使用拦截器Interceptor的. public class My1 ...
- mysql怎么查看当前登录用户
mysql> select user();+----------------+| user() |+----------------+| root@localhost |+--- ...