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 ±1ms2. 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 t3tN
v1 v2 v3vN

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

Copy
1
100
30

Sample Output 1

Copy
2100.000000000000000

The maximum distance is achieved when a train runs as follows:

  • In the first 30 seconds, it accelerates at a rate of 1ms2, covering 450 meters.
  • In the subsequent 40 seconds, it maintains the velocity of 30ms, covering 1200 meters.
  • In the last 30 seconds, it decelerates at the acceleration of −1ms2, covering 450 meters.

The total distance covered is 450 + 1200 + 450 = 2100 meters.


Sample Input 2

Copy
2
60 50
34 38

Sample Output 2

Copy
2632.000000000000000

The maximum distance is achieved when a train runs as follows:

  • In the first 34 seconds, it accelerates at a rate of 1ms2, covering 578 meters.
  • In the subsequent 26 seconds, it maintains the velocity of 34ms, covering 884 meters.
  • In the subsequent 4 seconds, it accelerates at a rate of 1ms2, covering 144 meters.
  • In the subsequent 8 seconds, it maintains the velocity of 38ms, covering 304 meters.
  • In the last 38 seconds, it decelerates at the acceleration of −1ms2, covering 722 meters.

The total distance covered is 578 + 884 + 144 + 304 + 722 = 2632 meters.


Sample Input 3

Copy
3
12 14 2
6 2 7

Sample Output 3

Copy
76.000000000000000

The maximum distance is achieved when a train runs as follows:

  • In the first 6 seconds, it accelerates at a rate of 1ms2, covering 18 meters.
  • In the subsequent 2 seconds, it maintains the velocity of 6ms, covering 12 meters.
  • In the subsequent 4 seconds, it decelerates at the acceleration of −1ms2, covering 16 meters.
  • In the subsequent 14 seconds, it maintains the velocity of 2ms, covering 28 meters.
  • In the last 2 seconds, it decelerates at the acceleration of −1ms2, covering 2 meters.

The total distance covered is 18 + 12 + 16 + 28 + 2 = 76 meters.


Sample Input 4

Copy
1
9
10

Sample Output 4

Copy
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 1ms2, covering 10.125 meters.
  • In the last 4.5 seconds, it decelerates at the acceleration of −1ms2, covering 10.125 meters.

The total distance covered is 10.125 + 10.125 = 20.25 meters.


Sample Input 5

Copy
10
64 55 27 35 76 119 7 18 49 100
29 19 31 39 27 48 41 87 55 70

Sample Output 5

Copy
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(数学+二分)的更多相关文章

  1. HDU 6216 A Cubic number and A Cubic Number(数学/二分查找)

    题意: 给定一个素数p(p <= 1e12),问是否存在一对立方差等于p. 分析: 根据平方差公式: 因为p是一个素数, 所以只能拆分成 1*p, 所以 a-b = 1. 然后代入a = b + ...

  2. UVA 10668 - Expanding Rods(数学+二分)

    UVA 10668 - Expanding Rods 题目链接 题意:给定一个铁棒,如图中加热会变成一段圆弧,长度为L′=(1+nc)l,问这时和原来位置的高度之差 思路:画一下图能够非常easy推出 ...

  3. Success Rate CodeForces - 807C (数学+二分)

    You are an experienced Codeforces user. Today you found out that during your activity on Codeforces ...

  4. CF 483B. Friends and Presents 数学 (二分) 难度:1

    B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input stand ...

  5. AtCoder Non-decreasing(数学思维)

    题目链接:https://abc081.contest.atcoder.jp/tasks/arc086_b 题目大意:有n个数,最多可以执行2*n次操作,每次可以选择将ai加到aj上,最终使得该序列满 ...

  6. HDU 5646 DZY Loves Partition 数学 二分

    DZY Loves Partition 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5646 Description DZY loves parti ...

  7. UVA 11881 Internal Rate of Return(数学+二分)

    In finance, Internal Rate of Return (IRR) is the discount rate of an investment when NPV equals zero ...

  8. ACM学习历程—HDU5587 Array(数学 && 二分 && 记忆化 || 数位DP)(BestCoder Round #64 (div.2) 1003)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5587 题目大意就是初始有一个1,然后每次操作都是先在序列后面添加一个0,然后把原序列添加到0后面,然后 ...

  9. AtCoder ABC 076D - AtCoder Express

    传送门:http://abc076.contest.atcoder.jp/tasks/abc076_d 本题是一个运动学问题——匀变速运动. 一个质点,从静止开始运动.按照速度限制,可将运动划分成n个 ...

随机推荐

  1. 表单提交时上传图片 表单ajax提交

    页面 <script type="text/javascript" src="js/jquery.form.js"></script>& ...

  2. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-如何获取标准驱动器扭矩值获取电流值

    双击某个驱动器(以松下伺服驱动器为例),在Process Data中,注意默认显示了PDO mapping1的数据(Error code, status word等)   注意左侧,2和3分别表示了与 ...

  3. 微信小程序 的文字复制功能如何实现?

    text设置属性  selectable="true" 就可以长按复制了 文章来源:刘俊涛的博客 地址:http://www.cnblogs.com/lovebing 欢迎关注,有 ...

  4. 小米miui系统怎么关闭文件管理里的热门视频和表情?

    小米miui系统怎么关闭文件管理里的热门视频和表情? 打开"文件管理"后,切换到"手机"选项卡. 然后,点击屏幕右上角的一排竖点. . 在弹出的菜单中点击&qu ...

  5. HDU 4632 Palindrome subsequence(区间dp)

    Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65535 K (Java/ ...

  6. 判断一个字符串是否为合法IP

    输入任意一个字符串,判断是否为合法IP bool IsIPAddress(const char * str){ //先判断形式是否合法, //检查是否只包含点和数字 ; str[i] != '\0'; ...

  7. MATLAB 的字符串分析

    MATLAB的字符串分析. 字符串实际上是指1Xn 的字符数组. MATLAB软件具有强大的字符串处理功能,提供了很多的字符或字符串处理函数,包括字符串的创建.字符串的属性.比较.查找以及字符串的转换 ...

  8. 【MyBatis学习09】高级映射之一对多查询

    上一篇博文总结了一下一对一的映射,本文主要总结一下一对多的映射,从上一篇文章中的映射关系图中可知,订单项和订单明细是一对多的关系,所以本文主要来查询订单表,然后关联订单明细表,这样就有一对多的问题出来 ...

  9. NSDate相差8小时

     NSDate *date = [NSDate date]; NSTimeZone *zone = [NSTimeZone systemTimeZone]; NSInteger interval = ...

  10. Python绘制分段函数

    1.绘制分段函数:y=4sin(4πt)-sgn(t-0.3)-sgn(0.72-t) import numpy as npimport matplotlib.pyplot as plt#绘制分段函数 ...