HDU 5033
题意: 给你 N 楼房, 然后给你m个人站在这些楼房之间, 问看到天空的仰角是多少度
思路: 对于每一个人, 算出左边的凸包, 和右边的凸包, 找出最大斜率点, 算角度即可
(我在线算比较费时, 离线可以省时间)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const double INF=2e9;
const int maxn = 1e5 + 131;
const double PI = acos(-1.0);
const double eps = 1e-8;
struct Point
{
double x, y;
int pos;
Point(int x = 0,int y = 0): x(x), y(y) {}
//Point(){}
}; int dcmp(double x)
{
if(fabs(x) < eps) return 0;
if(x < 0) return -1;
else return 1;
} typedef Point Vector;
Vector operator + (Vector A, Vector B) { return Vector(A.x+B.x, A.y+B.y); }
Vector operator - (Point A, Point B) { return Vector(A.x-B.x, A.y-B.y); }
bool operator < (Point A, Point B) { return A.x < B.x; }
int Cross(Vector A, Vector B) { return dcmp(A.x*B.y - A.y*B.x); }
double Dot(Vector A, Vector B) { return double(A.x*B.x + A.y*B.y); }
double Length(Vector A) { return sqrt(Dot(A, A)); }
double Angle(Vector A, Vector B) { return acos(Dot(A,B) / Length(A) / Length(B)); } Point p[maxn], ch[maxn];
int PreL[maxn], PreR[maxn]; void ConVexHull(Point *p, int n, Point *ch)
{
int m = 0;
PreL[0] = 0;
for(int i = 0; i < n; ++i) {
while(m > 1 && dcmp(Cross(ch[m-1] - ch[m-2], p[i]-ch[m-2]) > 0)) m--;
ch[m++] = p[i];
if(i) PreL[i] = ch[m-2].pos;
}
m = 0;
PreR[n-1] = n-1;
for(int i = n-1; i >= 0; --i) {
while(m > 1 && dcmp(Cross(ch[m-1] - ch[m-2], p[i]-ch[m-2]) < 0)) m--;
ch[m++] = p[i];
if(n-1-i) PreR[i] = ch[m-2].pos;
}
}
int lb(double xx,int n)
{
int left = 0, right = n;
p[n].x = INF;
while(left < right)
{
int mid=(left+right)>>1;
if(xx<p[mid].x)
right=mid;
else
left=mid+1;
}
return left-1;
} int main()
{
int t;
scanf("%d",&t);
for(int kase = 1; kase <= t; ++kase)
{
int n;
scanf("%d",&n);
for(int i = 0; i < n; ++i)
{
scanf("%lf%lf", &p[i].x, &p[i].y);
}
sort(p,p+n);
for(int i = 0; i < n; ++i) p[i].pos = i;
ConVexHull(p,n,ch);
/*for(int i = 0; i < n; ++i)
cout << PreL[i] << " ";
cout <<endl;
for(int i = 0; i < n; ++i)
cout << PreR[i] << " ";
cout <<endl;*/
int Q; double pos;
scanf("%d",&Q);
printf("Case #%d:\n",kase);
while(Q--)
{
scanf("%lf",&pos);
int lll = lb(pos,n);
int rrr = lll + 1;
Point New(pos, 0);
/*cout << New.x << " " << New.y <<endl;
cout << p[lll].x << " " << p[lll].y << endl;
cout << p[rrr].x << " " << p[rrr].y << endl;
cout << "***********************\n";
cout << p[PreL[lll]].x << " " << p[PreL[lll]].y <<endl;
cout << p[n-PreR[rrr]-1].x << " " << p[n-1-PreR[rrr]].y <<endl;*/
Vector L, R;
while(dcmp(Cross(p[lll]-New, p[PreL[lll]]-New) < 0)) lll = PreL[lll];
L = p[lll]-New; while(dcmp(Cross(p[rrr]-New, p[PreR[rrr]]-New) > 0)) rrr = PreR[rrr];
R = p[rrr] - New; //cout << "L : \n" << L.x << " " << L.y<< endl;
//cout << "R : \n" << R.x << " " << R.y<< endl;
double Degree = fabs(Angle(L,R)*180 / PI);
printf("%.10f\n",Degree);
}
}
}
HDU 5033的更多相关文章
- HDU 5033 Building(单调栈)
HDU 5033 Building(单调栈) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5033 Description Once upon a ti ...
- hdu 5033 buiding(单调栈)
hdu 5033 buiding(单调栈) 某年某月某天,马特去了一个小镇.这个小镇如此狭窄,以至于他可以把小镇当作一个枢纽.在镇上有一些摩天大楼,其中一栋位于xi,高度为hi.所有的摩天大楼位于不同 ...
- HDU 5033 Building
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5033 解题报告:在一条x轴上有n个建筑物,每个建筑物有一个高度h,然后现在有q次查询,查询的内容是假设 ...
- hdu 5033 模拟+单调优化
http://acm.hdu.edu.cn/showproblem.php?pid=5033 平面上有n个建筑,每个建筑由(xi,hi)表示,m组询问在某一个点能看到天空的视角范围大小. 维护一个凸包 ...
- hdu - 5033 - Building(单调栈)
题意:N 幢楼排成一列(1<=N<=10^5),各楼有横坐标 xi(1<=xi<=10^7) 以及高度 hi(1<=hi<=10^7),在各楼之间的Q个位置(1&l ...
- HDU 5033 Building(北京网络赛B题) 单调栈 找规律
做了三天,,,终于a了... 11724203 2014-09-25 09:37:44 Accepted 5033 781MS 7400K 4751 B G++ czy Building Time L ...
- hdu 5033 单调栈 ****
看出来是单调栈维护斜率,但是不会写,2333,原来是和询问放在一起的 #include <iostream> #include <cstdio> #include <cs ...
- HDU 5033 Building --离线+单调栈
题意:给一些建筑物,x表示横坐标,h表示高度,然后查询某些坐标x,问从该点看向天空的最大张角是多大. 解法:离线操作,读入所有数据,然后按x升序排序,对每一个查询的x,先从左到右,依次添加x坐标小于x ...
- HDU 5033 (单调栈维护凸包) Building
题意: 一个人在x轴上,他的左右两侧都有高楼,给出楼的横坐标Xi和高度Hi还有人的位置pos,求人所能看到的天空的最大角度. 分析: 将建筑物和人的位置从左到右排序,对于每个位置利用栈求一次人左边建筑 ...
- HDU 5033 Building(单调栈维护凸包)
盗张图:来自http://blog.csdn.net/xuechelingxiao/article/details/39494433 题目大意:有一排建筑物坐落在一条直线上,每个建筑物都有一定的高度, ...
随机推荐
- svn各种表示含义及解决
- node 跨域请求设置
http.createServer((req,res)=>{ //设置允许跨域的域名,*代表允许任意域名跨域 res.setHeader("Access-Control-Allow-O ...
- vue实现简单的全选、反选、不选
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- int、bool和str
int bit_length 返回以二进制表示的最短长度 print(int.bit_length(10)) 结果 4 Process finished with exit code 0 int() ...
- Kettle系列: Kettle并行执行Trans后的合并问题
我们在作业开发中为了处理效率, 经常需要并行执行一些trans, 等它们执行完毕后, 需要执行另外一些trans, 从流程上也就是分支+汇合. 粗看起来很简单, Kettle中对接一下这些组件就搞定了 ...
- 通用化NPOI导出xls
前言:在导出到xls时有一些通用的元素,比如标题,列标题,内容区域,求和行,但每个xls多少有点不同,为了处理这个问题,可以使用delegate实现,这样可以把差异部分单独处理. //为了处理计算和之 ...
- html去掉滑动条
实例: .week { /*text-align: left;*/ /*display: inline-table;*/ margin: 0 auto; padding: 0; list-style: ...
- 第28月第11天 vim -b
1. 首先以二进制方式编辑这个文件: vim -b datafile现在用 xxd 把这个文件转换成十六进制: :%!xxd文本看起来像这样: 0000000 ...
- LAS(Listener、Attender、Speller)端到端构架
基于注意力(Attention)机制的端到端系统,又被称为LAS端到端构架. [6] W. Chan, N. Jaitly, Q. Le, O. Vinyals. Listen, Attend and ...
- Java -cp 命令行引用多个jar包的简单写法(Windows、Linux
1.Windows下用法 在Windows上,可以使用 用法:java your-jar-lib-folder/* your-main-class your-jar-lib-folder为存放一堆ja ...