题目链接: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. 蓝牙BLE LINK LAYER剖析(一) -- status and channel

    一.LINK LAYER STATES 二.PHYSICAL CHANNEL

  2. Java 进程(转)

    转自http://jiangshuiy.iteye.com/blog/1674235 PS:今天做android助手项目的时候,发现adb push命令执行会卡死,最后发现不能用waitfor阻塞等待 ...

  3. LightOj1054 - Efficient Pseudo Code ( 求n的m次方的因子和 )

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1054 题意:给你两个数n和m, 求n^m的所有因子和,结果对1000000007求余; ...

  4. Linux console on LCD

    有时候需要将开机启动的信息输出到LCD上,并且在终端上进行调试.本文记录更改的方法. 参考链接 http://blog.csdn.net/chenbang110/article/details/787 ...

  5. python笔记 - day5

    python笔记 - day5 参考: http://www.cnblogs.com/wupeiqi/articles/5484747.html http://www.cnblogs.com/alex ...

  6. C语言:通过返回指针的形式找出数组的最大值和最小值

    // //  main.c //  Pointer_max_min(return) // //  Created by ma c on 15/8/2. //  Copyright (c) 2015年 ...

  7. 微信公众平台开发(84) 小i机器人

    很多朋友询问如何开发小黄鸡之类的智能聊天机器人,但遗憾的是小黄鸡接口申请页面在最近几个月里都无法访问,且使用时限制太大,我们找了另一个接口:小i机器人.本文介绍如何在微信公众平台中使用小i接口开发智能 ...

  8. 不连数据库List分页

    package com.jpsycn.kfwggl.common.crawl; import java.util.ArrayList; import java.util.List; public cl ...

  9. OC中@property属性关键字的使用(assign/weak/strong/copy)

    OC中@property属性关键字的使用(assign/weak/strong/copy) 一.assign 用于 ‘基本数据类型’.‘枚举’.‘结构体’ 等非OC对象类型 eg:int.bool等 ...

  10. 使单元格td内部都是超链接

    楼主是想要鼠标指针移到单元格时就显示手形,而且点击单元格的任何地方都可以打开链接,来替换原来要鼠标指针移到链接文字时才显示手形,和必须点中链接文字才能打开链接? 试一下: <table>  ...