题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816

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.
 
————————————————————————————————————————————————————————————————————————————————
贴一下官方题解:

题目大意:
在海平面上找一点投放潜水艇,投放的准确地点存在误差D,求最大的潜水深度期望。
题目分析:
即在海平面下再画一条折线,然后用间距为2×D的竖线将图截出,求截出的图形的最大面积。
解法:
可以看出当将两竖线不断右移的过程中,除了一种状态以外,其余状态对于面积的影响均为单调的。
此状态为当左边竖线所相交的折线为向上趋势并且右边竖线所相交的折线为向下趋势并且在到达端点前,两竖线与折线的交点的高度为相同的值时,此时面积最大。
所以,可以直接将两竖线从左往右移动,每次移动一个端点的距离,如果出现该情况则计算中途可能出现的最大面积,否则记录当前最大面积,即可于O(N)时间内得出结果。

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

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

代码(2390MS):

 #include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef long double LDB; const int MAXN = ;
const LDB EPS = 1e-; 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));
if(sgn(a) < ) {
LDB t = - b / / a;
if(sgn(l - t) <= && 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];
return Game(a, * v * a + b, a * v * v + b * v + c);
} LDB area(int pos) {
return (y[pos] + y[pos + ]) / 2.0 * (x[pos + ] - x[pos]);
} LDB solve() {
if(d == ) {
int res = ;
for(int i = ; i <= n; ++i) res = max(res, y[i]);
return res;
}
LDB nowx = , res = , s = ;
int l = , r = ;
while(r < n && x[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;
if(sgn(x[l + ] - nowx) == ) s -= area(l++), nowx = x[l];
if(sgn(x[r + ] - nowx - d) == ) s += area(r++), nowx = x[r] - d;
}
return res / d;
} int main() {
scanf("%d", &T);
while(T--) {
scanf("%d%d", &n, &L);
for(int i = ; i <= n; ++i) scanf("%d%d", &x[i], &y[i]);
x[n + ] = x[n];
scanf("%d", &d); d <<= ;
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. 2015 ACM/ICPC Asia Regional Changchun Online HDU 5444 Elven Postman【二叉排序树的建树和遍历查找】

    Elven Postman Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  9. 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 ...

随机推荐

  1. [daily][device] linux挂载iphone

    头几个月去旅游,亲戚的iphone照了好多照片,空间不足.就备份在了我的电脑上. 那么问题就是如何在linux系统里挂载iphone? 我找到了这篇文档,然而我没看. https://wiki.arc ...

  2. spring容器IOC创建对象<二>

    问题?spring是如何创建对象的?什么时候创建对象?有几种创建方式?测试对象是单例的还是多例的 ?对象的初始化和销毁? 下面的四大模块IOC的内容了!需要深刻理解 SpringIOC定义:把对象的创 ...

  3. ::after,::before使用

    ::after,::before使用   1.:before 选择器在被选元素的内容前面插入内容. 请使用 content 属性来指定要插入的内容. <!DOCTYPE html> < ...

  4. ios 消息传递机制

    引用文章 一.KVO 1.当对象中的某个属性值发生了改变,可以对这些值的观察者做出通知. 2.接受者(会接收到值发生改变的消息) 必须知道发送者(值将发生改变的那个对象). 3.接收者同样还需要知道发 ...

  5. Qt 之 设置窗口边框的圆角(使用QSS和PaintEvent两种方法)

    Qt在设置窗口边框圆角时有两种方式,一种是设置样式,另一种是在paintEvent事件中绘制窗口.下面分别叙述用这两种方式来实现窗口边框圆角的效果. 一.使用setStyleSheet方法 this- ...

  6. 规则html表单对象赋值

    function grid_load_callback(data, status) {            if (data.rows.length > 0)            {     ...

  7. PowerDesigner生成SQL Server 2008脚本注释乱码的问题

    [%OWNER%?[.O:[execute ][exec ]]sp_addextendedproperty [%R%?[N]]'MS_Description', N[%R%?[N]]%.q:COMME ...

  8. [LeetCode]题解(python):041-First Missing Positive

    题目来源 https://leetcode.com/problems/first-missing-positive/ Given an unsorted integer array, find the ...

  9. Windows7下 配置 Apache + PHP + MySQL + Zend Studio配置

    相关软件下载: Apache                               版本:(httpd-2.2.25) PHP                                   ...

  10. stretchableImageWithLeftCapWidth 的使用方法

    - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight: (NSInteger)topCa ...