2019 Multi-University Training Contest 1 D Vacation 思维

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6581

题意:n+1辆车,每辆车有个位置,长度和速度,求第一辆车到达终点的时间

题解:第一辆车肯定会以这n+1辆车的某辆车的速度到达终点,所以就枚举一下这n+1辆车,求个时间的最大值即可

#include 
using namespace std;
const int N =  1e5 + 10;
double s[N], v[N], l[N], sum[N];
int n;
int main() {
	double ans;
	while(~scanf("%d", &n)) {
		
		for(int i = 1; i <= n + 1; i++) {
			scanf("%lf", &l[i]);
			sum[i] = sum[i - 1] + l[i];
		}
		for(int i = 1; i <= n + 1; i++)
			scanf("%lf", &s[i]);
			
		for(int i = 1; i <= n + 1; i++)
			scanf("%lf", &v[i]);
			
		ans = 0;
		for(int i = 1; i <= n + 1; i++) {
			
			ans = max(ans, (s[i] + sum[i] - l[1]) / v[i]);
		}
		printf("%.10f\n", ans);
	}
	return 0;
} 

 

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