hdu 5033 模拟+单调优化
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 模拟+单调优化的更多相关文章
- HDU 5033 Building(单调栈)
HDU 5033 Building(单调栈) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5033 Description Once upon a ti ...
- hdu 5033 Building (单调栈 或 暴力枚举 )
Description Once upon a time Matt went to a small town. The town was so small and narrow that he can ...
- HDU - 5033 Building (单调栈+倍增)
题意:有一排建筑,每座建筑有一定的高度,宽度可以忽略,求在某点的平地上能看到天空的最大角度. 网上的做法基本都是离线的...其实这道题是可以在线做的. 对于向右能看到的最大角度,从右往左倍增维护每个时 ...
- HDU 5033 Building(单调栈维护凸包)
盗张图:来自http://blog.csdn.net/xuechelingxiao/article/details/39494433 题目大意:有一排建筑物坐落在一条直线上,每个建筑物都有一定的高度, ...
- hdu 5033 buiding(单调栈)
hdu 5033 buiding(单调栈) 某年某月某天,马特去了一个小镇.这个小镇如此狭窄,以至于他可以把小镇当作一个枢纽.在镇上有一些摩天大楼,其中一栋位于xi,高度为hi.所有的摩天大楼位于不同 ...
- HDU - 5033: Building(单调栈 ,求一排高楼中人看楼的最大仰角)
pro:现在在X轴上有N个摩天大楼,以及Q个人,人和大楼的坐标各不相同,保证每个人左边和右边都有楼,问每个人能看到天空的角度大小. sol:不难想到就是维护凸包,此题就是让你模拟斜率优化,此处没有斜率 ...
- hdu 2829 Lawrence(斜率优化DP)
题目链接:hdu 2829 Lawrence 题意: 在一条直线型的铁路上,每个站点有各自的权重num[i],每一段铁路(边)的权重(题目上说是战略价值什么的好像)是能经过这条边的所有站点的乘积之和. ...
- HDU 2920 分块底数优化 暴力
其实和昨天写的那道水题是一样的,注意爆LL $1<=n,k<=1e9$,$\sum\limits_{i=1}^{n}(k \mod i) = nk - \sum\limits_{i=1}^ ...
- hdu 4928 Series 2 (优化+模拟)
题意: 一个含n个数的序列a,每两个相邻的数相减得到一个新数,这些数组成一个新的序列. 假设全部得到的序列都满足非严格的单调性.则原序列为nice series.假设给出的序列 本来不满足单调性.它是 ...
随机推荐
- 第一个struct2程序
[第1步] 安装Struts2 这一步对于Struts1.x和Struts2都是必须的,只是安装的方法不同.Struts1的入口点是一个Servlet,而Struts2的入口点是一个过滤器(Filte ...
- array numpy 模块
高级用法:http://www.jb51.net/article/87987.htm from array import * 调用 array 与 import numpy as np 调用 np. ...
- VScode 安装必备
1.运行程序:
- golang获取IP地址
ip:=this.Ctx.Request.RemoteAddr ip=ip[0:strings.LastIndex(ip, ":")]
- clipboard.js复制文字
A-固定内容: <script type="text/javascript" src="script/clipboard.min.js"></ ...
- 第六章 图(a)概述
- 基于Python Shell获取hostname和fqdn释疑
一直以来被Linux的hostname和fqdn(Fully Qualified Domain Name)困惑了好久,今天专门抽时间把它们的使用细节弄清了. 一.设置hostname/fqdn 在Li ...
- linux中使用locate搜索文件方法记录
在linux中,有时用apt或者yum等软件包管理工具直接安装软件的时候,不知道软件到底安装到哪里去了,配置文件放哪里?这个时候就可以使用搜索命令locate来找到这些文件.海词上locate翻译为找 ...
- JavaScript对象继续总结
1.字符串对象 18_1.查看字符串的长度 var a = "hello world" alert(a.length) 18_2.遍历整个字符串的,这里的是索引 for (var ...
- Linux跑火车,提升趣味性
實現跑火車[可陶冶情操,愉悦心情]##下载yum源[root@localhost ~]# wget http://mirror.centos.org/centos/7/extras/x86_64/P ...