看出来是单调栈维护斜率,但是不会写,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. Fibonacci 2

    Fibonacci 2 感谢613的提供的题面 题目描述 给定\(S_0,S_1\),\(S_n=S_{n-1}+S_{n-2}+F_nF_{n-1}\),求\(S_n\bmod 2^{32}\). ...

  2. 转:jQuery弹出二级菜单

    <html> <head> <meta http-equiv="content-type" content="text/html; char ...

  3. SqlServer coalesce函数

    SqlServer数据库中coalesce函数用法:在SqlServer2005中有了新的函数,它非常的实用,它就是coalesce函数,此函数可以返回参数中的第一个非空表达式,当你要在N个字段中选取 ...

  4. Oracle 与 entity framework 6 的配置,文档

    官方文档: http://docs.oracle.com/cd/E56485_01/win.121/e55744/intro001.htm#ODPNT123 Oracle 对 微软 实体框架 EF6 ...

  5. Java for LeetCode 218 The Skyline Problem【HARD】

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  6. 省市县联动dropdownlist

    下面就是在提交按钮的单击事件中填写代码(代码区)(前提是把省市县的数据库建好) protected void Page_Load(object sender, EventArgs e)         ...

  7. ref 和 out

    两者都是按地址传递的,使用后都将改变原来的数值.很多人在论坛上解释说out是按数值传递,是错误的.简单的测试后可以知道out使用也能改变数值的,所以肯定是按照地址传递的.其次:rel可以把参数的数值传 ...

  8. 调用c++接口类

    调用c++接口类 public class CarDeviceDll { /*对dll库进行一些初始化*/ [DllImport("IDI.dll")] public static ...

  9. October 13th 2016 Week 42nd Thursday

    If the world seems cold to you, kindle fires to warm it. 若世界以寒相待,请点燃火堆以温暖相报. Kindle fires to warm th ...

  10. NYOJ题目836画图

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsoAAAMbCAIAAADb4SQpAAAgAElEQVR4nO3du1Iq3dYG4H0T5l6IMR