AtCoder Express(数学+二分)
D - AtCoder Express
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
In the year 2168, AtCoder Inc., which is much larger than now, is starting a limited express train service called AtCoder Express.
In the plan developed by the president Takahashi, the trains will run as follows:
- A train will run for (t1+t2+t3+…+tN) seconds.
- In the first t1 seconds, a train must run at a speed of at most v1 m/s (meters per second). Similarly, in the subsequent t2 seconds, a train must run at a speed of at mostv2 m/s, and so on.
According to the specifications of the trains, the acceleration of a train must be always within ±1m⁄s2. Additionally, a train must stop at the beginning and the end of the run.
Find the maximum possible distance that a train can cover in the run.
Constraints
- 1≤N≤100
- 1≤ti≤200
- 1≤vi≤100
- All input values are integers.
Input
Input is given from Standard Input in the following format:
N
t1 t2 t3 … tN
v1 v2 v3 … vN
Output
Print the maximum possible that a train can cover in the run.
Output is considered correct if its absolute difference from the judge's output is at most 10−3.
Sample Input 1
1
100
30
Sample Output 1
2100.000000000000000
The maximum distance is achieved when a train runs as follows:
- In the first 30 seconds, it accelerates at a rate of 1m⁄s2, covering 450 meters.
- In the subsequent 40 seconds, it maintains the velocity of 30m⁄s, covering 1200 meters.
- In the last 30 seconds, it decelerates at the acceleration of −1m⁄s2, covering 450 meters.
The total distance covered is 450 + 1200 + 450 = 2100 meters.
Sample Input 2
2
60 50
34 38
Sample Output 2
2632.000000000000000
The maximum distance is achieved when a train runs as follows:
- In the first 34 seconds, it accelerates at a rate of 1m⁄s2, covering 578 meters.
- In the subsequent 26 seconds, it maintains the velocity of 34m⁄s, covering 884 meters.
- In the subsequent 4 seconds, it accelerates at a rate of 1m⁄s2, covering 144 meters.
- In the subsequent 8 seconds, it maintains the velocity of 38m⁄s, covering 304 meters.
- In the last 38 seconds, it decelerates at the acceleration of −1m⁄s2, covering 722 meters.
The total distance covered is 578 + 884 + 144 + 304 + 722 = 2632 meters.
Sample Input 3
3
12 14 2
6 2 7
Sample Output 3
76.000000000000000
The maximum distance is achieved when a train runs as follows:
- In the first 6 seconds, it accelerates at a rate of 1m⁄s2, covering 18 meters.
- In the subsequent 2 seconds, it maintains the velocity of 6m⁄s, covering 12 meters.
- In the subsequent 4 seconds, it decelerates at the acceleration of −1m⁄s2, covering 16 meters.
- In the subsequent 14 seconds, it maintains the velocity of 2m⁄s, covering 28 meters.
- In the last 2 seconds, it decelerates at the acceleration of −1m⁄s2, covering 2 meters.
The total distance covered is 18 + 12 + 16 + 28 + 2 = 76 meters.
Sample Input 4
1
9
10
Sample Output 4
20.250000000000000000
The maximum distance is achieved when a train runs as follows:
- In the first 4.5 seconds, it accelerates at a rate of 1m⁄s2, covering 10.125 meters.
- In the last 4.5 seconds, it decelerates at the acceleration of −1m⁄s2, covering 10.125 meters.
The total distance covered is 10.125 + 10.125 = 20.25 meters.
Sample Input 5
10
64 55 27 35 76 119 7 18 49 100
29 19 31 39 27 48 41 87 55 70
Sample Output 5
20291.000000000000 //题意:读了老半天,就是说一列火车在 n 段路上行驶,给出行驶的时间,和最大速度限制,起点终点速度要为 0 ,问最大可行驶的路程是多少?
//应该是头次做这种题吧, 所以,做的比较慢,先逆序扫一遍,可得到在每段路上行驶,为了到终点为 0 速度,限制速度是多少。
然后正序累加,具体操作是,二分(加速时间+匀速时间)的最大值,然后就可以轻松解决了
# include <bits/stdc++.h>
using namespace std;
# define eps 1e-
# define INF 1e20
# define pi acos(-1.0)
# define MX
struct Node
{
double t,v;
double ev; //从终点的最大速度
}seg[MX]; int n;
double spd, ans; void gogo(int x)
{
double l=, r=seg[x].t;
double res = ;
while (l<r-eps) // <
{
double mid = (l+r)/;
if (mid + spd > seg[x].v-eps)
{
if ((seg[x].v - seg[x+].ev) + mid < seg[x].t+eps)
{
res = mid;
l = mid;
}
else r = mid;
}
else
{
if (mid + spd - (seg[x].t-mid) - seg[x+].ev < -eps) //<=
{
res = mid;
l = mid;
}
else r = mid;
}
} double jia, yun, jian;
if (spd + res < seg[x].v)
{
jia = res;
yun = ;
jian = seg[x].t - jia;
}
else
{
jia = seg[x].v - spd;
yun = res - jia;
jian = seg[x].t - jia - yun;
}
ans += 1.0/2.0*jia*jia + spd * jia;
ans += yun * seg[x].v; if (res+spd < seg[x].v)
{
ans += -1.0/2.0*jian*jian + (spd+jia) * jian;
spd = spd + jia - jian;
}
else
{
ans += -1.0/2.0*jian*jian + seg[x].v * jian;
spd = seg[x].v - jian;
} } int main()
{
scanf("%d",&n);
for (int i=;i<=n;i++)
scanf("%lf",&seg[i].t);
for (int i=;i<=n;i++)
scanf("%lf",&seg[i].v);
spd=0.0;
for (int i=n;i>=;i--)
{
if (spd+seg[i].t < seg[i].v+eps) //<=
spd += seg[i].t;
else
spd = seg[i].v;
seg[i].ev = spd;
}
ans = ;
spd = ;
seg[n+] = (Node){0.0, 0.0, 0.0}; for (int i=;i<=n;i++)
{
gogo(i);
}
printf("%.5f\n",ans);
return ;
}
AtCoder Express(数学+二分)的更多相关文章
- HDU 6216 A Cubic number and A Cubic Number(数学/二分查找)
题意: 给定一个素数p(p <= 1e12),问是否存在一对立方差等于p. 分析: 根据平方差公式: 因为p是一个素数, 所以只能拆分成 1*p, 所以 a-b = 1. 然后代入a = b + ...
- UVA 10668 - Expanding Rods(数学+二分)
UVA 10668 - Expanding Rods 题目链接 题意:给定一个铁棒,如图中加热会变成一段圆弧,长度为L′=(1+nc)l,问这时和原来位置的高度之差 思路:画一下图能够非常easy推出 ...
- Success Rate CodeForces - 807C (数学+二分)
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces ...
- CF 483B. Friends and Presents 数学 (二分) 难度:1
B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input stand ...
- AtCoder Non-decreasing(数学思维)
题目链接:https://abc081.contest.atcoder.jp/tasks/arc086_b 题目大意:有n个数,最多可以执行2*n次操作,每次可以选择将ai加到aj上,最终使得该序列满 ...
- HDU 5646 DZY Loves Partition 数学 二分
DZY Loves Partition 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5646 Description DZY loves parti ...
- UVA 11881 Internal Rate of Return(数学+二分)
In finance, Internal Rate of Return (IRR) is the discount rate of an investment when NPV equals zero ...
- ACM学习历程—HDU5587 Array(数学 && 二分 && 记忆化 || 数位DP)(BestCoder Round #64 (div.2) 1003)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5587 题目大意就是初始有一个1,然后每次操作都是先在序列后面添加一个0,然后把原序列添加到0后面,然后 ...
- AtCoder ABC 076D - AtCoder Express
传送门:http://abc076.contest.atcoder.jp/tasks/abc076_d 本题是一个运动学问题——匀变速运动. 一个质点,从静止开始运动.按照速度限制,可将运动划分成n个 ...
随机推荐
- 炫酷的sublimeText开发工具 快捷键总结
sublimeText3绝对是写前端程序的利器.占内存小.启动快.代码提示功能齐全,界面酷炫并且再也不怕断电.了 网上搜罗一些快捷键总结一下.先来张图: (事实上sublimeText3也能够写 ...
- CentOS 5 全功能WWW服务器搭建全教程 V3.0
http://hx100.blog.51cto.com/44326/339949/ 一.基本系统安装1.下载CentOS 5我是下载的DVD版本,大家也可以下载服务器CD安装版本,其实都差不多.大家可 ...
- java.net.ConnectException: failed to connect to /10.0.2.2 (port 80): connect
在使用GENYMOTION作为Android程序调试模拟器连接web服务器时,报了:java.net.ConnectException: failed to connect to /10.0.2.2 ...
- iOS项目中的网络请求和上下拉刷新封装
代码地址如下:http://www.demodashi.com/demo/11621.html 一.运行效果图 现在的项目中不可避免的要使用到网络请求,而且几乎所有软件都有上下拉刷新功能,所以我在此对 ...
- Smooks转换设计
Smooks转换设计 背景 不同的合作银行对应的外部接口是不一样的,我们需要把外部这些变化不定的接口格式,转换为我们银保通系统可以识别的内部接口.Smooks可以很好的解决这一问题.并且,当合作银行的 ...
- Mac 上的传奇效率神器 Alfred 3
下载地址:https://www.alfredapp.com/ 第三方教程:https://www.jianshu.com/p/e9f3352c785f 一.内置快捷键介绍 1.默认快捷呼出热键是: ...
- 深入理解get和post的区别
GET和POST是HTTP请求的两种基本方法,要说它们的区别,接触过WEB开发的人都能说出一二.最直观的区别就是GET把参数包含在URL中,POST通过request body传递参数. 正常GET和 ...
- 一步步教你如何进行Xilinx SerDes调试
FPGA SERDES的应用需要考虑到板级硬件,SERDES参数和使用,应用协议等方面.由于这种复杂性,SERDES的调试工作对很多工程师来说是一个挑战.本文将描述SERDES的一般调试方法,便于工程 ...
- Strategy模式
Strategy模式 Strategy模式要解决的问题和Template模式类似.都是为了把算法的声明和算法的实现解耦.Template模式是通过继承来实现的,而Strategy模式是通过组合来实现的 ...
- 【Java】取当前.class文件的编译位置
本文与<[C++]求当前exe的执行路径>(点击打开链接)为姊妹篇.C++在win下生成的执行文件是.exe.Java生成的执行文件是.class然后自己主动扔到Java虚拟机中执行.主要 ...