HDU 4816 Bathysphere(数学)(2013 Asia Regional Changchun)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816
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.
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.
题目大意:
在海平面上找一点投放潜水艇,投放的准确地点存在误差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)的更多相关文章
- 2013 Asia Regional Changchun C
Little Tiger vs. Deep Monkey Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K ( ...
- HDU 4822 Tri-war(LCA树上倍增)(2013 Asia Regional Changchun)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4822 Problem Description Three countries, Red, Yellow ...
- 2013 Asia Regional Changchun I 题,HDU(4821),Hash
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4821 解题报告:搞了很久,总算搞出来了,还是参考了一下网上的解法,的确很巧,和上次湘潭的比 ...
- HDU 4816 Bathysphere (2013长春现场赛D题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...
- 2013 Asia Regional Changchun
Hard Code http://acm.hdu.edu.cn/showproblem.php?pid=4813 #include<cstdio> ]; int main(){ int t ...
- (并查集)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 ...
- (二叉树)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) ...
- 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 ...
- 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 ...
随机推荐
- [转]正则表达式相关:C# 抓取网页类(获取网页中所有信息)
using System; using System.Data; using System.Configuration; using System.Net; using System.IO; usin ...
- MySQL数据库表名、列名、别名区分大小写的问题
MySQL在Linux下数据库名.表名.列名.别名大小写规则是这样的: 1.数据库名与表名是严格区分大小写的: 2.表的别名是严格区分大小写的: 3.列名与列的别名在所有的情况下均是忽略大小写的: 4 ...
- 【Android测试】【第一节】性能——CPU
◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5065083.html 前言 本来打算写完全部的自动化测试之 ...
- eclipse如何修改dynamic web module version
eclipse如何修改dynamic web module version 一.修改工程属性: 右键eclipse的工程,选择属性,再选择Project Facets里面中选择Dynamic Web ...
- C++经典编程题#1:含k个3的数
总时间限制: 1000ms 内存限制: 65536kB 描述 输入两个正整数 m 和 k,其中1 < m < 100000,1 < k < 5 ,判断 m 能否被19整除, ...
- 选择时区的命令tzselect
选择时区的命令tzselect tzselectPlease identify a location so that time zone rules can be set correctly.Plea ...
- Activity的四种启动模式-图文并茂
1.对于使用standard 模式的活动,系统不会在乎这个活动是否已经在返回栈中存在,每次启动都会创建该活动的一个新的实例. 例如A启动A,A再接着启动A,A继续启动A,然后再分别出栈,如图所示 ...
- Android中制作自定义dialog对话框的实例
http://www.jb51.net/article/83319.htm 这篇文章主要介绍了Android中制作自定义dialog对话框的实例分享,安卓自带的Dialog显然不够用,因而我们要继 ...
- Redis 安全性设置
redis安装好后,默认情况下登陆客户端和使用命令操作时不需要密码的.某些情况下,为了安全起见,我们可以设置在客户端连接后进行任何操作之前都要进行密码验证. 我这边是安装的window系统,修改red ...
- Unity3D 插件大全
2D_Toolkit 2d动画开发插件包 FingerGestures 触摸插件 ORK_Okashi_RPG_Kit Unity3D角色扮演游戏开发工具包 uScript-Visual-Script ...