Problem Description
Once upon a time Matt went to a small town. The town was so small and narrow that he can regard the town as a pivot. There were some skyscrapers in the town, each located at position xi with its height hi. All skyscrapers located in different place. The skyscrapers had no width, to make it simple. As the skyscrapers were so high, Matt could hardly see the sky.Given the position Matt was at, he wanted to know how large the angle range was where he could see the sky. Assume that Matt's height is 0. It's guaranteed that for each query, there is at least one building on both Matt's left and right, and no building locate at his position.
 
Input
The first line of the input contains an integer T, denoting the number of testcases. Then T test cases follow.

Each test case begins with a number N(1<=N<=10^5), the number of buildings.

In the following N lines, each line contains two numbers, xi(1<=xi<=10^7) and hi(1<=hi<=10^7).

After that, there's a number Q(1<=Q<=10^5) for the number of queries.

In the following Q lines, each line contains one number qi, which is the position Matt was at.

 
Output
For each test case, first output one line "Case #x:", where x is the case number (starting from 1).

Then for each query, you should output the angle range Matt could see the sky in degrees. The relative error of the answer should be no more than 10^(-4).

 
Sample Input
3
3
1 2
2 1
5 1
1
4
3
1 3
2 2
5 1
1
4
3
1 4
2 3
5 1
1
4
 
Sample Output
Case #1:
101.3099324740
Case #2:
90.0000000000
Case #3:
78.6900675260
 
Source
 
 
Recommend
hujie   |   We have carefully selected several similar problems for you:  6521 6520 6519 6518 6517 
思路:

将建筑物和人的位置从左到右排序,对于每个位置利用栈求一次人左边建筑物的凸包,找到一个最小的角度,然后对称一下,再找一个右边的建筑物的最小角度,两个角度加起来就是答案。

将人左边的建筑物从左到右扫描,下面两种情况会出栈:

  1. 栈顶元素楼高小于等于当前扫描到的楼高,因此这是一个单调的栈
  2. 栈顶两个楼顶所在直线的斜率 小于 栈顶的楼顶和当前楼顶所在直线的斜率(这里的斜率指的是绝对值),这保证了栈中所有楼顶的构成的曲线是个凸包

然后再求人的视线和竖直线的最小角度时,如果栈顶的楼的人的视线与水平线夹角 大于 栈中第二个楼所成的夹角,则出栈

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<map>
#include<cmath> const int maxn=1e5+;
typedef long long ll;
using namespace std;
const double pi = acos(-1.0);
pair<double, double> p[maxn];
pair<double, int> pos[maxn];
double ans[maxn];
int stack[maxn], n, Q; double slope(const int a, const int b)
{
return -(p[a].second - p[b].second) / (p[a].first - p[b].first);
} double angle(const int a, const int b)
{
return atan((pos[b].first - p[a].first) / p[a].second);
} void solve()
{
int j = , top = ;
for(int i = ; i < Q; ++i)
{
while(j < n && p[j].first < pos[i].first)
{
while(top > && p[stack[top]].second <= p[j].second) top--;
while(top >= && slope(stack[top], j) < slope(stack[top - ], stack[top])) top--;
stack[++top] = j;
j++;
}
while(top >= && angle(stack[top], i) > angle(stack[top - ], i)) top--;
ans[pos[i].second] += angle(stack[top], i);
}
} int main()
{
int T, kase;
scanf("%d", &T);
for(int kase = ; kase <= T; ++kase)
{
scanf("%d", &n);
for(int i = ; i < n; ++i)
scanf("%lf%lf", &p[i].first, &p[i].second);
sort(p, p + n); scanf("%d", &Q);
for(int i = ; i < Q; ++i)
{
scanf("%lf", &pos[i].first);
pos[i].second = i;
ans[i] = 0.0;
}
sort(pos, pos + Q);
solve();
reverse(p, p + n);
reverse(pos, pos + Q);
for(int i = ; i < n; ++i) p[i].first = -p[i].first;
for(int i = ; i < Q; ++i) pos[i].first = -pos[i].first;
solve();
printf("Case #%d:\n", kase);
for(int i = ; i < Q; ++i)
printf("%.10lf\n", ans[i]/pi*180.0);
}
return ;
}
 

Building(单调栈+凸包)的更多相关文章

  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. HDU5033 building 单调栈+计算几何

    正解:单调栈 解题报告: 哇生气辽QAQ本来打了半天feel good都快调出来了然后说换题了QAQ(所以可能那题的代码会过一阵子再放上来了QAQ 不过还是大爆手速打了一通拿到首杀了嘻嘻 美滋滋辽 然 ...

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

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

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

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

  6. BZOJ_1007_ [HNOI2008]_水平可见直线_(单调栈+凸包)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1007 给出一些直线,沿着y轴从上往下看,能看到多少条直线. 分析 由于直线相交,会遮挡住一些直 ...

  7. HDU5033 Building(单调栈)

    题意是说在水平轴上有很多建筑物(没有宽度),知道每个建筑物的位置与高度.有m个查询,每次查询位置x所能看到的天空的角度. 方法是将建筑与查询一起排序,从左往右计算一遍,如果是建筑物,则比较最后两个(当 ...

  8. hdu5033 Building (单调栈+)

    http://acm.hdu.edu.cn/showproblem.php?pid=5033 2014 ACM/ICPC Asia Regional Beijing Online B 1002 Bui ...

  9. CF535E Tavas and Pashmaks 单调栈、凸包

    传送门 题意:有一场比赛,$N$个人参加.每个人有两种参数$a,b$,如果存在正实数$A,B$使得$\frac{A}{a_i} + \frac{B}{b_i}$在$i=x$处取得最大值(可以有多个最大 ...

随机推荐

  1. dos下mybatis自动生成代码

    今天来介绍下怎么用mybatis-gennerator插件自动生成mybatis所需要的dao.bean.mapper xml文件,这样我们可以节省一部分精力,把精力放在业务逻辑上. 之前看过很多文章 ...

  2. Ant Design Pro入门教程,安装,运行(V5 Typescript版)

    [前言] 找了很多Admin模板,最后还是看中了AntDesignPro这个阿里巴巴开源的Admin框架,长这样(还行吧,目前挺主流的): 官网地址:https://pro.ant.design/in ...

  3. 16、Java中级进阶 面向对象 封装

    1.封装概述 封装可以被认为是一个保护屏障,将类的某些信息隐藏在类内部,不允许外部程序直接访问,而是通过类提供的方法来实现对隐藏信息的操作访问,可以有效的防止该类的代码和数据被其他类随意访问. 要访问 ...

  4. Zabbix5 Frame 嵌套

    Zabbix5 Frame 嵌套 Zabbix 默认不允许嵌套在其他页面上,通过修改配置允许嵌套 找到 Zabbix 下面的 include/defines.inc.php 文件,末尾有一行 defi ...

  5. 排查Mysql突然变慢的一次过程

    排查Mysql突然变慢的一次过程 上周客户说系统突然变得很慢,而且时不时的蹦出一个 404 和 500,弄得真的是很没面子,而恰巧出问题的时候正在深圳出差,所以一直没有时间 看问题,一直到今天,才算是 ...

  6. notepad++ 设置支持golang语法高亮

    see https://stackoverflow.com/questions/27747457/golang-plugin-on-notepad

  7. Linux用户锁定、解锁及锁定查看

    [root@l01 ~]# passwd -S pispread pispread PS -- - (Password set, SHA512 crypt.)用户锁定 [root@l01 ~]# pa ...

  8. 简谈DFS

    所谓DFS就是“不撞南墙不回头”的一种搜索.其时间复杂度为O(V+E). 能算出从起点到终点的全部路径,在算法执行的过程中需要一个visit[vi]数组来维护每个结点的访问情况,这样就能避免重复访问. ...

  9. K8S 创建管理员账号

    一.生成管理员证书 cat > admin-csr.json <<EOF { "CN": "admin", "hosts" ...

  10. Alink漫谈(十八) :源码解析 之 多列字符串编码MultiStringIndexer

    Alink漫谈(十八) :源码解析 之 多列字符串编码MultiStringIndexer 目录 Alink漫谈(十八) :源码解析 之 多列字符串编码MultiStringIndexer 0x00 ...