HDU6581 Vacation (HDU2019多校第一场1004)

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

题意:

给你n+1辆汽车,每辆汽车有汽车的长度L,汽车距离终点的距离S,汽车的最大速度V

汽车与汽车之间距离为0时,速度大的汽车的速度会等于速度小的汽车的速度

求离终点最远的那辆车的车头到达终点的时间

注意,当汽车驶过终点线后会继续行驶,相遇,对后面的车也会造成影响

题解:

这里谈一下O(n)的写法

首先,当我们的最后一辆车不会与其他车相遇时,我们能得到答案为s[0]/v[0];

然后,我们假设,所有车都相遇了的情况

如图所示,最后一辆车刚好到达终点时,与到数第二辆车相遇,于此同时,这n+1辆车现在全部以第一辆车的速度v[n]行驶,那么我们也很容易求得,最后一辆车的车头到达终点的时间恰好是第一辆车到达pos位置的时间

\(t=(\sum_{1}^{n}L_i+sn)/v_n\)

有了这两种极限情况我们就可以想,如果我们的最后一辆车与前面任意一辆车相撞,我们最后一辆车最后到达终点的时间都是用相撞的最前面那辆车来计算的,每多撞上一辆车,我们的时间都响应的会变慢,也就是变大,于是我们保存的最大值就是最后一辆车相遇的时间了,如图所示,我就算到倒数第三辆车就算出答案了

代码:

#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define ls rt<<1
#define rs rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define bug printf("*********\n")
#define FIN freopen("input.txt","r",stdin);
#define FON freopen("output.txt","w+",stdout);
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
#define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
#define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n"
const int maxn = 3e5 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
LL quick_pow(LL x, LL y) {
LL ans = 1;
while(y) {
if(y & 1) {
ans = ans * x % mod;
} x = x * x % mod;
y >>= 1;
} return ans;
}
int l[maxn], s[maxn], v[maxn];
int main() {
#ifndef ONLINE_JUDGE
FIN
#endif
int n;
while(~scanf("%d", &n)) {
for(int i = 0; i <= n; i++) scanf("%d", &l[i]);
for(int i = 0; i <= n; i++) scanf("%d", &s[i]);
for(int i = 0; i <= n; i++) scanf("%d", &v[i]);
double ans = s[0] * 1.0 / v[0];
int sum = 0;
for(int i = 1; i <= n; i++) {
sum += l[i];
ans = max(ans, (sum + s[i]) * 1.0 / v[i]);
}
printf("%.10f\n", ans);
}
return 0;
}

最新文章

  1. ASP.NET MVC5----了解我们使用的@HTML帮助类
  2. java.lang.ClassNotFoundException: com.mysql.jdbc.Driver解决办法
  3. maven web项目中web.xml
  4. Linux4:useradd、userdel、passwd、groupadd、chgrp、chown、df、du、sort、wget
  5. BIEE 后台新建分析没有你创建的数据源
  6. php用soap创建webservice
  7. django 学习-18 用户管理Auth系统使用
  8. HTML5入门2---js获取HTML元素的值
  9. 获取或设置checkbox radio select的值
  10. Oracle的dual表是个什么东东
  11. 深入理解OkHttp源码(三)——网络操作
  12. MySQL Binlog常用参数
  13. linux下编译upx 3.93
  14. 消息 8101,级别 16,状态 1,第 1 行 仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表&#39;ResourceInfo&#39;中的标识列指定显式值。
  15. 移动端Retina屏边框线1px 显示为2px或3px问题解决方法
  16. 对一道pwnhub的一点点记录
  17. HDUOJ--Holding Bin-Laden Captive!
  18. 将Oracle数据库设置为归档模式及非归档模式
  19. bzoj 5120 [2017国家集训队测试]无限之环——网络流
  20. css3之背景属性之background-size

热门文章

  1. [已转移]IE事件流和DOM标准事件流的区别
  2. mysql 语句的查询过程解析
  3. 阿里云OSS同城冗余存储技术解析
  4. pycharm 快捷键使用
  5. DOTA轮播
  6. C# 星期相关代码实例
  7. ∆ (triangle)
  8. PageHelper实现分页查询
  9. OpenCV 安装与调试
  10. git提交空目录的方法