看出来是单调栈维护斜率,但是不会写,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. MySQL 临时表的使用

    -- step 1.创建临时表,命名为item_orders create temporary table item_orders ( item_id int, orderList ) ) -- st ...

  2. http get vs post

    http get vs post GET与POST方法有以下区别:(1) 在客户端,Get方式在通过URL提交数据,数据在URL中可以看到:POST方式,数据放置在HTML HEADER内提交.(2) ...

  3. java压缩

    /* @description:压缩文件操作 * @param filePath 要压缩的文件路径 * @param descDir 压缩文件保存的路径 d:\\aaa.zip */ public s ...

  4. Sql Server事务简单用法

    var conStr = "server=localhost;database=Data;user=sa;pwd=123456"; using (var connection = ...

  5. stream的seek方法实例

    using (FileStream outStream = new FileStream(@"D:\12.txt", FileMode.Open)) { using (FileSt ...

  6. Django~Models1

    不用数据库不用Models 省却 --------------- startapp urls +链接 view以下 ---------------- 添加Model 在project/settings ...

  7. SAP ALV显示并打印(非OO方式)

    *&---------------------------------------------------------------------* *& Report  Z_SD_CPF ...

  8. java基础学习05(面向对象基础01)

    面向对象基础01 1.理解面向对象的概念 2.掌握类与对象的概念3.掌握类的封装性4.掌握类构造方法的使用 实现的目标 1.类与对象的关系.定义.使用 2.对象的创建格式,可以创建多个对象3.对象的内 ...

  9. Session原理浅析

    什么是Sesson? 简单说就是一个会话级的cookie,外加服务器端内存中一组散列表. 当你关闭浏览器的时候,这个cookie将消失. 这个cookie不写在磁盘上,而是存在于浏览器缓存. 关于Se ...

  10. 【leetcode】Bitwise AND of Numbers Range(middle)

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...