杭电2019多校第一场 HDU——6581 Vacation (思维)

时间限制: 1 Sec  内存限制: 128 MB  Special Judge

题目描述

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.

 

输入

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]

 

输出

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.

 

样例输入

复制样例数据

1
2 2
7 1
2 1
2
1 2 2
10 7 1
6 2 1

样例输出

3.5000000000
5.0000000000

题意:  给出一个n表示一个车前面还有n个车,然后是n+1列,每一列有三个数表示一辆车的车长、车头距离停车线的距离、车的速度,求那最后一个车到达停车线的距离,所有车始终匀速行驶,而且注意前面的车过路口后速度不变继续向前行驶。题目保证给出的车不会重叠,最多是头挨着尾。

题解:从后往前(相对于车与停车线的位置来说的,注意:不是说的i的先后)依次计算所有情况即可~~太奇妙了,菜鸡我没想到~后来懂了后发现我曹了,真水~~

上代码:

#include 
#include 
#include 
using namespace std;
typedef long long ll;
const int MAX = 1e6+100;
double dp[MAX],l[MAX],s[MAX],v[MAX];
int main(){
	int n;
	while(cin >> n){
		double maxx=0;
		for (int i = 0; i <= n;i++) cin >> l[i];
		for (int i = 0; i <= n;i++) cin >> s[i];
		for (int i = 0; i <= n;i++) cin >> v[i];
		for (int i = 1; i <= n;i++) dp[i]=dp[i-1]+l[i];//统计所有车长的前缀和
		for (int i = 0; i <= n;i++) maxx=max(maxx,(dp[i]+s[i])/v[i]);//计算所有情况
		printf("%.10f\n",maxx);
	}
	return 0;
} 

 

你可能感兴趣的:(思维)