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. apply和call用法

    资料来源:http://blog.csdn.net/business122/article/details/8000676 Js apply方法详解 我在一开始看到javascript的函数apply ...

  2. cmd 字符串截取

    @echo off set "url=www.mzwu.com" echo 1.字符串截取 echo %url:~4,4% echo %url:~4,-4% echo %url:~ ...

  3. blast及其格式输出简介

    1)blast产生背景 双序列比对可以采用是基于动态规划算法的Needleman-Wunsch(NW)和Smith-Waterman algorithm(SW)算法,虽然精度高,但计算消耗大.当与数据 ...

  4. 利用R求分位数及画出箱型图

    1)数据集 data<-c(75.0,64.0,47.4,66.9,62.2,62.2,58.7,63.5,66.6,64.0,57.0,69.0,56.9,50.0,72.0) 默认是四分位: ...

  5. Array Product(模拟)

    Array Product http://codeforces.com/problemset/problem/1042/C You are given an array aa consisting o ...

  6. Java的三种多线程

    项目结构 继承Thread类 /* * Thread类实现了Runnable接口 */ public class MyThread extends Thread { @Override public ...

  7. Writing A Better JavaScript Library For The DOM 阅读记录

    原文地址:http://coding.smashingmagazine.com/2014/01/13/better-javascript-library-for-the-dom/ 主要观点: live ...

  8. 零基础学习hadoop到上手工作线路指导(编程篇)

    问题导读: 1.hadoop编程需要哪些基础? 2.hadoop编程需要注意哪些问题? 3.如何创建mapreduce程序及其包含几部分? 4.如何远程连接eclipse,可能会遇到什么问题? 5.如 ...

  9. dede中arcurl的解析

    有时候我们需要在dede中通过$dsql查询出文章数据,并生成文章的地址. 但是dede默认的dede_archives和附加表dede_addonarticle都没有存放arcurl的字段. 说明a ...

  10. MongoDb进阶实践之四 MongoDB查询命令详述

    一.引言 上一篇文章我们已经介绍了MongoDB数据库的最基本操作,包括数据库的创建.使用和删除数据库,文档的操作也涉及到了文档的创建.删除.更新和查询,当然也包括集合的创建.重命名和删除.有了这些基 ...