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. JQUERY框架的优点与面试题

    1 你觉得 jquery 有哪些好处?jQuery 是轻量级的 javascript 框架强大的选择器出色的 DOM 操作的封装可靠的事件处理机制完善的 ajax 封装出色的浏览器的兼容性支持链式操作 ...

  2. Hive 和 HBase区别

    作者:yuan daisy 链接:https://www.zhihu.com/question/21677041/answer/78289309 来源:知乎 著作权归作者所有.商业转载请联系作者获得授 ...

  3. HTML 练习 做简历表

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. oracle 基本信息

    查看Oracle是32位还是64位的方法: 方法一:使用sqlplus 64位: [oracle@qs-wg-db2 ~]$ sqlplus / as sysdba;   SQL*Plus: Rele ...

  5. 出现了npm ERR! cb() never called!错误

    执行npm i 命令时,出现了npm ERR! cb() never called!错误 解决方案: 1.首先清除你的npm缓存: sudo npm cache clean -f 一般情况执行完后再试 ...

  6. Gviz

    1) Introduction 为了理解基因组数据,通常旨在在基因组浏览器中绘制这样的数据,以及各种基因组注释特征,例如基因或转录物模型,CpG岛,重复区域等.这些功能可以从ENSEMBL或UCSC等 ...

  7. org.Hs.eg.db包简介(转换NCBI、ensemble等数据库中基因ID,symbol等之间的转换)

    1)安装载入 ------------------------------------------- if("org.Hs.eg.db" %in% rownames(install ...

  8. 132. Palindrome Partitioning II (String; DP)

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  9. Space Ant(极角排序)

    Space Ant http://poj.org/problem?id=1696 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions ...

  10. mongo远程登录

    1. 进入数据库: use admin db.addUser("foo","foo"); ps:高版本用db.createUser创建. 2. 改配置 如/et ...