http://acm.hdu.edu.cn/showproblem.php?pid=5033

平面上有n个建筑,每个建筑由(xi,hi)表示,m组询问在某一个点能看到天空的视角范围大小。

维护一个凸包,据说可以用单调栈

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
const double pi = acos(-1.0);
const int INF = 2000000007;
map <double,int> hash;
struct node{
double x,h;
}s[100005];
int n,ll[100005],rr[100005];
double ans;
set <double> st;
bool cmp(node a,node b)
{
return a.x < b.x;
}
int main(){
int _,q,cas = 1;
RD(_);
while(_--){
printf("Case #%d:\n",cas++);
RD(n);
st.clear();
hash.clear();
for(int i = 1;i <= n;++i){
scanf("%lf%lf",&s[i].x,&s[i].h);
ll[i] = rr[i] = i;
st.insert(s[i].x);
}
sort(s+1,s+n+1,cmp);
for(int i = 1;i <= n;++i){
hash[s[i].x] = i;
for(int j = i - 1;j >= 1;--j){
if(s[j].h > s[i].h){
ll[i] = j;
break;
}
if(j == ll[j]) break;
}
}
for(int i = n;i >= 1;--i){
for(int j = i + 1;j <= n;++j){
if(s[j].h > s[i].h){
rr[i] = j;
break;
}
if(j == rr[j]) break;
}
}
RD(q);
while(q--){
double x;
scanf("%lf",&x);
int r = hash[*st.lower_bound(x)],l = r - 1;
double bst = s[r].h/fabs(s[r].x - x);
while(r != rr[r]){
r = rr[r];
if(s[r].h > bst*(s[r].x-x))
bst = s[r].h/(s[r].x-x);
}
ans = pi - atan(bst);
bst = s[l].h/fabs(x - s[l].x);
while(l != ll[l]){
l = ll[l];
if(s[l].h > bst*(x-s[l].x))
bst = s[l].h/(x-s[l].x);
}
ans -= atan(bst);
printf("%.9lf\n",180.0*ans/pi);
}
}
return 0;
}

hdu 5033 模拟+单调优化的更多相关文章

  1. HDU 5033 Building(单调栈)

    HDU 5033 Building(单调栈) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5033 Description Once upon a ti ...

  2. hdu 5033 Building (单调栈 或 暴力枚举 )

    Description Once upon a time Matt went to a small town. The town was so small and narrow that he can ...

  3. HDU - 5033 Building (单调栈+倍增)

    题意:有一排建筑,每座建筑有一定的高度,宽度可以忽略,求在某点的平地上能看到天空的最大角度. 网上的做法基本都是离线的...其实这道题是可以在线做的. 对于向右能看到的最大角度,从右往左倍增维护每个时 ...

  4. HDU 5033 Building(单调栈维护凸包)

    盗张图:来自http://blog.csdn.net/xuechelingxiao/article/details/39494433 题目大意:有一排建筑物坐落在一条直线上,每个建筑物都有一定的高度, ...

  5. hdu 5033 buiding(单调栈)

    hdu 5033 buiding(单调栈) 某年某月某天,马特去了一个小镇.这个小镇如此狭窄,以至于他可以把小镇当作一个枢纽.在镇上有一些摩天大楼,其中一栋位于xi,高度为hi.所有的摩天大楼位于不同 ...

  6. HDU - 5033: Building(单调栈 ,求一排高楼中人看楼的最大仰角)

    pro:现在在X轴上有N个摩天大楼,以及Q个人,人和大楼的坐标各不相同,保证每个人左边和右边都有楼,问每个人能看到天空的角度大小. sol:不难想到就是维护凸包,此题就是让你模拟斜率优化,此处没有斜率 ...

  7. hdu 2829 Lawrence(斜率优化DP)

    题目链接:hdu 2829 Lawrence 题意: 在一条直线型的铁路上,每个站点有各自的权重num[i],每一段铁路(边)的权重(题目上说是战略价值什么的好像)是能经过这条边的所有站点的乘积之和. ...

  8. HDU 2920 分块底数优化 暴力

    其实和昨天写的那道水题是一样的,注意爆LL $1<=n,k<=1e9$,$\sum\limits_{i=1}^{n}(k \mod i) = nk - \sum\limits_{i=1}^ ...

  9. hdu 4928 Series 2 (优化+模拟)

    题意: 一个含n个数的序列a,每两个相邻的数相减得到一个新数,这些数组成一个新的序列. 假设全部得到的序列都满足非严格的单调性.则原序列为nice series.假设给出的序列 本来不满足单调性.它是 ...

随机推荐

  1. 框架中spring有专门的类用于处理乱码

    在三大框架spring中有专门的一个过滤器类用于处理乱码问题--->CharacterEncodingFilter 我们只需在web.xml中添加如下几行代码就可解决乱码问题 <filte ...

  2. Nsis Sqlite Plugin

    1.https://stackoverflow.com/questions/15346338/nsis-and-sqlite-integration 2.http://nsis.sourceforge ...

  3. 大型运输行业实战_day08_1_memcache缓存生产应用

    1.memcache使用环境搭建 1.安装memcached服务器 安装方法 以管理员身份打开cmd,在cmd中执行如下命令: 注意:在执行该命令时必须在memcached.exe文件下执行. 2.开 ...

  4. linux 用户管理(3)----查看用户登录时间以及命令历史

    1.查看当前登录用户信息 who命令: who缺省输出包括用户名.终端类型.登陆日期以及远程主机. who /var/log/wtmp 可以查看自从wtmp文件创建以来的每一次登陆情况 (1)-b:查 ...

  5. Docker三剑客之 Compose

    简介 Docker-Compose 是 Docker 的一种编排服务,是一个用于在 Docker 上定义并运行复杂应用的工具,可以让用户在集群中部署分布式应用. 通过 Docker-Compose 用 ...

  6. cin中函数的作用

    cin是istream类的对象,它是从标准输入设备(键盘)获取数据,程序中的变量通过流提取符">>"从流中提取数据.流提取符">>"从流 ...

  7. MongoDB 3.0 Release Notes

    MongoDB 3.0支持WiredTiger存储引擎,提供可插拔存储引擎API,新增SCRAM-SHA-1认证机制,改进explain功能. 可插拔存储引擎API 允许第三方为MongoDB开发存储 ...

  8. struts框架之总结OGNL表达式的特殊的符号

    1. # 符号的用法 * 获得contextMap中的数据 > <s:property value="#request.name"/> > <s:pr ...

  9. .net core webapi 部署windows server 2008 r2 笔记

    WebAPI部署文档 安装dotnet-dev-win-x64.1.0.4 安装DotNetCore.1.1.0-WindowsHosting 安装vc_redist.x64 安装Windows6.1 ...

  10. Mathtype使用技巧

    1. 打开/关闭MathType窗口 Alt+Ctrl+q:插入inline公式   Ctrl+S:更新公式到Word相应位置 Alt+F4:保存并关闭MathType窗口,返回Word. 2. 公式 ...