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个 ...
随机推荐
- 基于iOS 10、realm封装的下载器
代码地址如下:http://www.demodashi.com/demo/11653.html 概要 在决定自己封装一个下载器前,我本以为没有那么复杂,可在实际开发过程中困难重重,再加上iOS10和X ...
- oracle获取时间毫秒数
select (sysdate-to_date('1970-01-01','yyyy-mm-dd')-8/24)*24*60*60*1000-1* 60 * 60 * 1000 millisecon ...
- lua_pcall,lua_call 调用前后栈情况
lua_pcall和lua_call功能一样,只是lua_pcall提供了一个可以提供错误处理函数的功能 首先压入函数 ,再依次压入参数,现在你就可以调用lua_call了,函数调用后将参数,函数都弹 ...
- ibatis常用的集中判断语句
http://blog.csdn.net/liaomin416100569/article/details/5344483
- Html Table用JS导出excel格式问题 导出EXCEL后单元格里的000412341234会变成412341234 7-14 会变成 2018-7-14(7月14) 自定义格式 web利用table表格生成excel格式问题 js导出excel增加表头、mso-number-format定义数据格式 数字输出格式转换 mso-number-format:"\@"
Html Table用JS导出excel格式问题 我在网上找的JS把HTML Tabel导出成EXCEL.但是如果Table里的数字内容为0开的的导成Excel后会自动删除0,我想以text的格式写入 ...
- CEF与JavaScript交互读取电脑信息
CefSharp中c#和JavaScript交互读取电脑信息 介绍 CEF是由Marshall Greenblatt于2008年创建的基于Google Chromium的BSD许可开源项目.与主要关注 ...
- Silverlight实例教程 - Validation用户提交数据验证捕获(转载)
Silverlight 4 Validation验证实例系列 Silverlight实例教程 - Validation数据验证开篇 Silverlight实例教程 - Validation数据验证基础 ...
- unity, 集成iOS广告sdk注意事项
----更新:2015-10-22 今天在unity里集成讯飞语音听写的iOS sdk,结果发现前面集成domob广告的方法搞复杂了. 其实,直接把UnityViewControllerBase当做s ...
- gm picture
console.log("ok") /*var images = require("images");var fs = require("fs&quo ...
- java - day07 - PrimeNum
判断质数 package day06; import java.util.Scanner; //验证质数 public class primeNum { public static void main ...