看出来是单调栈维护斜率,但是不会写,2333,原来是和询问放在一起的

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
typedef __int64 ll;
using namespace std; const double PI = acos(-1.0);
const int maxn = ; struct Node {
int x, h;
bool operator <(const Node &a)const {
return x < a.x;
}
} node[maxn<<], stk[maxn<<];
double ans[maxn];
int n, q; int check(Node &a, Node &b, Node c) {
if (c.h <= )
c.h = ;
return (ll)(a.h - c.h) * (c.x - b.x) >= (ll)(b.h - c.h) * (c.x - a.x);
} double getAngle(Node a, Node b) {
return atan((double)(b.x-a.x)/(double)(a.h));
} void cal() {
int head = ;
for (int i = ; i < n+q; i++) {
if (node[i].h <= ) {
while (head >= && check(stk[head-], stk[head-], node[i]))
head--;
ans[-node[i].h] += getAngle(stk[head-], node[i]);
}
else {
while (head && stk[head-].h <= node[i].h)
head--;
while (head >= && check(stk[head-], stk[head-], node[i]))
head--;
stk[head++] = node[i];
}
}
} int main() {
int t, cas = ;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = ; i < n; i++)
scanf("%d%d", &node[i].x, &node[i].h);
scanf("%d", &q);
for (int i = ; i < q; i++) {
scanf("%d", &node[i+n].x);
node[i+n].h = -i;
} memset(ans, , sizeof(ans));
sort(node, node+n+q); cal(); reverse(node, node+n+q);
for (int i = ; i < n+q; i++)
node[i].x = - node[i].x; cal(); printf("Case #%d:\n", cas++);
for (int i = ; i < q; i++)
printf("%.10lf\n", ans[i] * 180.0 / PI);
}
return ;
}

hdu 5033 单调栈 ****的更多相关文章

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

    题意: 一个人在x轴上,他的左右两侧都有高楼,给出楼的横坐标Xi和高度Hi还有人的位置pos,求人所能看到的天空的最大角度. 分析: 将建筑物和人的位置从左到右排序,对于每个位置利用栈求一次人左边建筑 ...

  2. hdu 1506 单调栈问题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1506 题目的意思其实就是要找到一个尽可能大的矩形来完全覆盖这个矩形下的所有柱子,只能覆盖柱子,不能留空 ...

  3. hdu 5875(单调栈)

    Function Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  4. hdu 4923 单调栈

    http://acm.hdu.edu.cn/showproblem.php?pid=4923 给定一个序列a,元素由0,1组成,求一个序列b,元素在0~1之间,并且保证递增.输出最小的∑(ai−bi) ...

  5. hdu 3410 单调栈

    http://acm.hdu.edu.cn/showproblem.php?pid=3410 Passing the Message Time Limit: 2000/1000 MS (Java/Ot ...

  6. hdu 1505 单调栈升级版

    #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #defin ...

  7. hdu 1506 单调栈

    #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #defin ...

  8. HDU 5033 Building(单调栈)

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

  9. hdu - 5033 - Building(单调栈)

    题意:N 幢楼排成一列(1<=N<=10^5),各楼有横坐标 xi(1<=xi<=10^7) 以及高度 hi(1<=hi<=10^7),在各楼之间的Q个位置(1&l ...

随机推荐

  1. Yii中的错误及异常处理

    Yii中的错误及异常处理 Yii已经默认已经在CApplication上实现了异常和错误的接管,这是通过php的set_exception_handler, set_error_handler实现的. ...

  2. 【GoLang】GoLang struct 使用

    代码示例: package main import "fmt" type Human struct { name string age int weight int } type ...

  3. 1.JS设计模式-this,call&apply

    1. this,call&apply 1.1 this this是Javascript语言的一个关键字. 它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用. 1.1.1 普通函数调 ...

  4. 14. javacript高级程序设计-表单

    1. 表单脚本 1.1 基础知识 <from>元素表示表单: l acceptCharset:服务器能处理的字符集 l action:接受请求的URL l elements:表单中所有控件 ...

  5. Innodb锁机制:Next-Key Lock 浅谈

    数据库使用锁是为了支持更好的并发,提供数据的完整性和一致性.InnoDB是一个支持行锁的存储引擎,锁的类型有:共享锁(S).排他锁(X).意向共享(IS).意向排他(IX).为了提供更好的并发,Inn ...

  6. Centos6.5 SVN服务器 搭建及配置

    现有的项目开发中,版本控制机必不可少.合理的使用版本控制可以提高开发效果,在保证项目是最新的同时,也提高了源代码的安全性. 工具/原料 接入Internet的一台Centos6.5Linux计算机 安 ...

  7. Effective C++ -----条款22:将成员变量声明为private

    切记将成员变量声明为private.这可赋予客户访问数据的一致性.可细微划分访问控制.允诺约束条件获得保证,并提供class作者以充分的实现弹性. protected并不比public更具有封装性.

  8. 【leetcode】 Letter Combinations of a Phone Number(middle)

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  9. struts.xml配置

    1. package标签 package:完成有业务相关的Action(应用控制器的)管理 name:给包起的名字(反映该包中Action的功能),用来完成包和包之间的继承.默认继承struts-de ...

  10. asp.net DataSet数据导出到Excel中

    方法: [STAThread]///这是必须的    public override void VerifyRenderingInServerForm(System.Web.UI.Control co ...