题目链接: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. Java高级之线程同步

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 关于实现多线程的意义,"从业四年看并发"一文已经讲述,而本篇主要讲一下常用的设计 ...

  2. linux下连接本地的navicate

    1.进mysql cd mysql; cd bin; ./mysql -uroot -proot; show databases;#可以没有 #修改权限 1.GRANT ALL PRIVILEGES ...

  3. php--validate表单验证实例

    验证效果:

  4. MANIFEST.MF详解(转)

    转载自http://blog.csdn.net/zhifeiyu2008/article/details/8829637 打开Java的JAR文件我们经常可以看到文件中包含着一个META-INF目录, ...

  5. 20145211 《Java程序设计》第3周学习总结——绝知此事要躬行

    教材学习内容总结 4.1何为面向对象 面向对象,面向过程都是一种思想,没有高低之分.面向对象,就像是对冰箱操作,冰箱是一个介质,用法就像是c语言中的结构体,功能定义在对象上.面向对象,角色转变,让我们 ...

  6. cf707D. Persistent Bookcase(离线+dfs)

    题目链接:http://codeforces.com/problemset/problem/707/D  有一个n*m的书架,有K个操作,求每个操作后一共有多少本书:有4种操作: 1:x y 如果 x ...

  7. svn out of date

    out of date说明这个文件过期了,也就是已经有过一次提交的版本,当前提交的版本号小于当前的版本. 解决办法:先将文件update一下,然后再提交.

  8. js获取网站根目录

    //js获取网站根路径(站点及虚拟目录),获得网站的根目录或虚拟目录的根地址         function getRootPath(){        var strFullPath=window ...

  9. Date and Time Pattern

    The following examples show how date and time patterns are interpreted in the U.S. locale. The given ...

  10. 微信支付开发(2) 静态链接Native支付

    关键字:微信支付 微信支付v3 native支付 统一支付 Native支付 prepay_id 作者:方倍工作室原文: http://www.cnblogs.com/txw1958/p/wxpayv ...