hdu 5033 单调栈 ****
看出来是单调栈维护斜率,但是不会写,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 单调栈 ****的更多相关文章
- HDU 5033 (单调栈维护凸包) Building
题意: 一个人在x轴上,他的左右两侧都有高楼,给出楼的横坐标Xi和高度Hi还有人的位置pos,求人所能看到的天空的最大角度. 分析: 将建筑物和人的位置从左到右排序,对于每个位置利用栈求一次人左边建筑 ...
- hdu 1506 单调栈问题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1506 题目的意思其实就是要找到一个尽可能大的矩形来完全覆盖这个矩形下的所有柱子,只能覆盖柱子,不能留空 ...
- hdu 5875(单调栈)
Function Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- hdu 4923 单调栈
http://acm.hdu.edu.cn/showproblem.php?pid=4923 给定一个序列a,元素由0,1组成,求一个序列b,元素在0~1之间,并且保证递增.输出最小的∑(ai−bi) ...
- hdu 3410 单调栈
http://acm.hdu.edu.cn/showproblem.php?pid=3410 Passing the Message Time Limit: 2000/1000 MS (Java/Ot ...
- hdu 1505 单调栈升级版
#include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #defin ...
- hdu 1506 单调栈
#include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #defin ...
- HDU 5033 Building(单调栈)
HDU 5033 Building(单调栈) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5033 Description Once upon a ti ...
- hdu - 5033 - Building(单调栈)
题意:N 幢楼排成一列(1<=N<=10^5),各楼有横坐标 xi(1<=xi<=10^7) 以及高度 hi(1<=hi<=10^7),在各楼之间的Q个位置(1&l ...
随机推荐
- jquery为新增元素添加事件
<script type="text/javascript"> var $id=1; $(function(){ $(".hehe").click( ...
- MySQL 编程的6个重要的技巧
一.每一行命令都是用分号(;)作为结束 对于MySQL,第一件你必须牢记的是它的每一行命令都是用分号(;)作为结束的,但当一行MySQL被插入在PHP代码中时,最好把后面的分号省略掉,例如: 二. ...
- Git对象模型
原文:http://gitbook.liuhui998.com/1_2.html 一.SHA 在git中,所有用来表示项目历史信息的文件,是通过一个40个字符的(40-digit)"对象名& ...
- Design Elevator
From: https://discuss.leetcode.com/topic/89/write-elevator-program-using-event-driven-programming/9 ...
- ios xib 中的 size class
需要阅读UITraitCollection的说明文档,先截图如下: 今天说说xib中的size class的简单设置,先看图 一共有9个小块,水平方向代表width,垂直方向代表height. 对于w ...
- STL_fill()用法
以前很多次会给某个区间赋值,今天才知道有个函数可以满足这个功能. void fill (ForwardIterator first, ForwardIterator last, const T& ...
- Divide and conquer:Moo University - Financial Aid(POJ 2010)
Moo University - Financial Aid 其实是老题了http://www.cnblogs.com/Philip-Tell-Truth/p/4926008.html 这一次我们换二 ...
- codeforces 492C. Vanya and Exams 解题报告
题目链接:http://codeforces.com/problemset/problem/492/C 题目意思:给出 3 个整数:n, r, avg.然后有 n 行,每行有两个数:第 i 行有 ...
- 【leetcode】Swap Nodes in Pairs (middle)
Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...
- 【processing】小代码2
函数: 绘制直线自由图形: beginShape(), vertex(), endShape() 分别是绘制图形开始,连接图形的节点,绘制结束 endShape(CLOSE)表示闭合图形. 绘制曲线边 ...