Problem Description
The Bathysphere is a spherical deep-sea submersible which was unpowered and lowered into the ocean on a cable, and was used to conduct a series of dives under the sea. The Bathysphere was designed for studying undersea wildlife.

The Bathysphere was conducted from the deck of a ship. After counted, the ship should not move, so choosing the position where the Bathysphere was conducted is important.

A group of scientists want to study the secrets of undersea world along the equator, and they would like to use the Bathysphere. They want to choose the position where the Bathysphere can dive as deep as possible. Before conducting the Bathysphere, they have a map of the seabed, which tell them the shape of the seabed. They draw a line on the equator of the map to mark where they will release the Bathysphere, as a number axis. Suppose the axis is draw from 0 to L. But when they release the Bathysphere, they can't know where they are accurately, i.e., if they choose position x to release the Bathysphere, the real position will distribute between x-d and x+d with an equal probability, where d is given. The objective of the scientists is very simple, i.e., to maximize the expected depth.

For the ease of presentation, the shape of the seabed is described as a poly line. Given N points ) , ( Xi,Yi ) as the vertices, where Xi and Yi indicate the position and the depth of the i-th vertex, respectively, the ploy line is composed of the line segments that connect consecutive vertices.

Input
The first line contains an integer T (1 ≤ T ≤ 25), the number of test cases.

Then T test cases follow. In each test case, the first line contains two integers N (2 ≤ N ≤ 2*10^5) and L (2 ≤ L ≤ 10^9), as described above. Then N lines follow, each line contains two integer Xi and Yi (1≤i≤N, 0≤ Yi ≤10^9), where point ( Xi,Yi ) is a vertex of the ploy line. It is assumed that X1 == 0 and Xn == L and Xi < Xi+1 for 1 ≤ i < N. Then the following line contains one integer d (0 ≤ d ≤ L/2), as described above.

Output
For each test case, choose a position between d and L-d, both inclusive, to conducted the Bathysphere, and calculate the expected depth. Output the expected depth in a line, rounded to 3 digits after the decimal point.

————————————————————————————————————————————————————————————————————————————————

————————————————————————————————————————————————————————————————————————————————

PS：我写这题在HDU上不用long double就过不了。也完全不知道怎么用double过了，有知道怎么办的请务必告诉我！三分就不要了……

``` #include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef long double LDB;

;
;

inline int sgn(LDB x) {
return (x > EPS) - (x < -EPS);
}

int x[MAXN], y[MAXN];
int n, d, L, T;

struct Game {
LDB a, b, c;
Game() {}
Game(LDB a, LDB b, LDB c): a(a), b(b), c(c) {}
Game operator - (const Game &rhs) const {
return Game(a - rhs.a, b - rhs.b, c - rhs.c);
}
LDB val_at(LDB x) {
return a * x * x + b * x + c;
}
LDB max_val(LDB l, LDB r) {
LDB res = max(val_at(l), val_at(r));
) {
LDB t = - b /  / a;
&& sgn(t - r) <= )
res = val_at(t);
}
return res;
}
};

Game get(int pos, LDB v = 0.0) {
LDB k = LDB(y[pos + ] - y[pos]) / (x[pos + ] - x[pos]);
LDB t = y[pos] - k * x[pos];
LDB a = k / , b = t, c = -((k / ) * x[pos] + t) * x[pos];
* v * a + b, a * v * v + b * v + c);
}

LDB area(int pos) {
]) / ] - x[pos]);
}

LDB solve() {
) {
;
; i <= n; ++i) res = max(res, y[i]);
return res;
}
LDB nowx = , res = , s = ;
, r = ;
] <= d)
s += area(r++);
if(r == n) res = s;
while(r < n) {
LDB minx = min(x[l + ] - nowx, x[r + ] - nowx - d);
res = max(res, s + (get(r, d) - get(l)).max_val(nowx, nowx + minx));
nowx += minx;
] - nowx) == ) s -= area(l++), nowx = x[l];
] - nowx - d) == ) s += area(r++), nowx = x[r] - d;
}
return res / d;
}

int main() {
scanf("%d", &T);
while(T--) {
scanf("%d%d", &n, &L);
; i <= n; ++i) scanf("%d%d", &x[i], &y[i]);
x[n + ] = x[n];
scanf(;
printf("%.3f\n", (double)solve());
}
}```

## HDU 4816 Bathysphere（数学）（2013 Asia Regional Changchun）的更多相关文章

1. 2013 Asia Regional Changchun C

Little Tiger vs. Deep Monkey Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K ( ...

2. HDU 4822 Tri-war（LCA树上倍增）（2013 Asia Regional Changchun）

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4822 Problem Description Three countries, Red, Yellow ...

3. 2013 Asia Regional Changchun I 题，HDU(4821)，Hash

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4821 解题报告:搞了很久,总算搞出来了,还是参考了一下网上的解法,的确很巧,和上次湘潭的比 ...

4. HDU 4816 Bathysphere （2013长春现场赛D题）

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...

5. 2013 Asia Regional Changchun

Hard Code http://acm.hdu.edu.cn/showproblem.php?pid=4813 #include<cstdio> ]; int main(){ int t ...

6. （并查集）Travel -- hdu -- 5441（2015 ACM/ICPC Asia Regional Changchun Online ）

http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others)    Memo ...

7. （二叉树）Elven Postman -- HDU -- 54444（2015 ACM/ICPC Asia Regional Changchun Online）

http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Time Limit: 1500/1000 MS (Java/Others)  ...

8. hdu 5444 Elven Postman（二叉树）——2015 ACM/ICPC Asia Regional Changchun Online

Problem Description Elves are very peculiar creatures. As we all know, they can live for a very long ...

9. hdu 5868 2016 ACM/ICPC Asia Regional Dalian Online 1001 (burnside引理 polya定理）

Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K ...

## 随机推荐

1. How to Delete XML Publisher Data Definition Template

DECLARE  -- Change the following two parameters  VAR_TEMPLATECODE  VARCHAR2(100) := 'CUX_CHANGE_RPT1 ...

2. Android编码规范03

一.整个项目的目录规范化sundy老师建议有:系统目录规范.源代码目录规范. 1.系统目录规范: 指项目目录中不仅包括源代码,还需要包括:需求相关文档.设计文档.计划日志文档.测试文档.项目进行中学习 ...

3. http协议梳理（个人学习用）

HTTP默认的端口号为80,HTTPS的端口号为443. 在Internet中所有的传输都是通过TCP/IP进行的.HTTP协议作为TCP/IP模型中应用层的协议.HTTP协议通常承载于TCP协议之上 ...

4. ff

public class MyListenerProcessor implements BeanPostProcessor { @Override public Object postProcessB ...

5. 认识solr结构,了解核心的文件目录

下载solr并解压后,发现solr的目录里有很多的东西,此时我们可能会感到很恐慌,不知如何下手,下面让我带你认识它. 1.解压后的solr目录结构如下: 虽然里面有很多的文件,但是我们需要的其实就两个 ...

6. php set env

SYSTEM WARNING: 'date_default_timezone_get(): It is not safe to rely on the system's timezone settin ...

7. php编译错误Note that the MySQL client library is not bundled anymore!

Note that the MySQL client library is not bundled anymore! 解决方法. 1. 查看系统有没有安装mysql header find / -na ...

8. Apache URL重写规则

1.简介 Apached的重写功能,即是mod_rewrite模块功能,它是apache的一个模块.它的功能非常强大,可以操作URL中的所有部分. 因此我们就可以改写url,给用户提供一个简介大方的u ...

9. HashMap 源码分析

static final int DEFAULT_INITIAL_CAPACITY = 16;  默认容量 static final int MAXIMUM_CAPACITY = 1073741824 ...

10. （JavaScript）实现上传图片实时预览和（文件）大小判断

唉,为什么我一个做大数据和后端的要为前端耗尽心力啊??!! 昨天在做一个网页时遇到了一个问题,有一处需要插入图片,我原本的想法是获取到上传文件的URL,然后动态插入img标签,设置src为图片的URL ...