题目链接: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. Ajax 填充 前端页面

  2. phpcms标签整理_当前栏目调用

    phpcms标签整理_当前栏目调用 转载 **//SQL语句调用: {pc:get sql="select * from phpcms_category where catid in($ca ...

  3. Error executing aapt: Return code -1073741819

    在做andrid项目的时候,本来想把a项目中的a功能模块复制到b项目中,但是复制过程中出现xml文件id的问题, Error executing aapt: Return code -10737418 ...

  4. Sandbox 文件存放规则

    文档1, document2,  document3 一.文件路径介绍 <Application_Home>/AppName.app : 1) This is the bundle dir ...

  5. Node的Buffer

    var buf3 = new Buffer([1,2,3,4,-10,256],'utf8');//默认为utf8 console.log(buf3[0]);//正常的范围是0~255 console ...

  6. MongoDB上的索引

    1. 将索引建在number键上名为nameIndex并且为正序索引({number:-1}为倒序索引) 如: db.list名.ensureIndex({number:1},{name:" ...

  7. Java学习-037-JavaWeb_006 -- JSP 动作标识 - include

    这个动作是指在当前的页面中包含一个或多个 JSP 页面或者 HTML 文件,语法:<jsp:include file="../jsp/login.jsp" flush=&qu ...

  8. Tomcat 处理请求时的中文乱码问题

    利用Tomcat8作为服务器,采用servlet接收前端请求后进行处理的过程中,前台请求中有中文时,中文信息变成了乱码. 经过调试和查阅,发现Tomcat在处理get请求和post请求是有区别的.参照 ...

  9. JavaScript:实现瀑布流

    一.前言: 瀑布流现在是一个非常常用的布局方式了,尤其在购物平台上,例如蘑菇街,淘宝等等. 二.流程: 1.在html文件中写出布局的元素内容: 2.在css文件中整体对每一个必要的元素进行样式和浮动 ...

  10. linux上配置java环境

    四.安装JDKsudo rpm -ivh jdk-7u75-linux-x64.rpmsudo rpm -qd jdk //查看jdk安装路径:/usr/java/jdk1.7.0_75/ 五.编辑环 ...