题意: 给你 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的更多相关文章

  1. HDU 5033 Building(单调栈)

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

  2. hdu 5033 buiding(单调栈)

    hdu 5033 buiding(单调栈) 某年某月某天,马特去了一个小镇.这个小镇如此狭窄,以至于他可以把小镇当作一个枢纽.在镇上有一些摩天大楼,其中一栋位于xi,高度为hi.所有的摩天大楼位于不同 ...

  3. HDU 5033 Building

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5033 解题报告:在一条x轴上有n个建筑物,每个建筑物有一个高度h,然后现在有q次查询,查询的内容是假设 ...

  4. hdu 5033 模拟+单调优化

    http://acm.hdu.edu.cn/showproblem.php?pid=5033 平面上有n个建筑,每个建筑由(xi,hi)表示,m组询问在某一个点能看到天空的视角范围大小. 维护一个凸包 ...

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

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

  6. HDU 5033 Building(北京网络赛B题) 单调栈 找规律

    做了三天,,,终于a了... 11724203 2014-09-25 09:37:44 Accepted 5033 781MS 7400K 4751 B G++ czy Building Time L ...

  7. hdu 5033 单调栈 ****

    看出来是单调栈维护斜率,但是不会写,2333,原来是和询问放在一起的 #include <iostream> #include <cstdio> #include <cs ...

  8. HDU 5033 Building --离线+单调栈

    题意:给一些建筑物,x表示横坐标,h表示高度,然后查询某些坐标x,问从该点看向天空的最大张角是多大. 解法:离线操作,读入所有数据,然后按x升序排序,对每一个查询的x,先从左到右,依次添加x坐标小于x ...

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

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

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

    盗张图:来自http://blog.csdn.net/xuechelingxiao/article/details/39494433 题目大意:有一排建筑物坐落在一条直线上,每个建筑物都有一定的高度, ...

随机推荐

  1. IO流--字符流与字节流--File类常用功能

    IO流的常用方法: 1: 文件的读取和写入图解: 2:字节流: 读写文件的方法: 一般效率读取: 读取文件:        FileInputStream(); 写数据:            Fil ...

  2. 10.tesseract

    1.Tesseract-OCR简介  一个Google支持的开源的OCR图文识别开源项目.支持多种语言(我使用的是3.02 版本,支持包括英文,简体中文,繁体中文),支持Windows,Linux,M ...

  3. redis整合Spring集群搭建及业务中的使用

    1.redis安装 Redis是c语言开发的. 安装redis需要c语言的编译环境.如果没有gcc需要在线安装.yum install gcc-c++ 安装步骤: 第一步:redis的源码包上传到li ...

  4. GCC编译器原理(二)------编译原理一:目标文件

    一.目标文件 在 UNIX® 和 Linux® 中,任何事物都是文件.UNIX 和 Linux 编程实际上是编写处理各种文件的代码.系统由许多类型的文件组成,但目标文件具有一种特殊的设计,提供了灵活和 ...

  5. Play XML Entities

    链接:https://pentesterlab.com/exercises/play_xxe/course Introduction This course details the exploitat ...

  6. Redis Fun使用

    using Newtonsoft.Json; using StackExchange.Redis; using System; using System.Configuration; using Sy ...

  7. pyqt5模块介绍

    python各种库介绍  https://wiki.python.org/moin/GuiProgramming PyQt5.QtWidgets     包含控件 PyQt5.QtGui      图 ...

  8. 对Tomcat部署web应用的方式总结

    对Tomcat部署web应用的方式总结,常见的有以下四种: 1.[使用控制台部署] 访问Http://localhost:8080,并通过Tomcat Manager登录,进入部署界面即可. 2.[利 ...

  9. 【译】第四篇 SQL Server安全权限

    本篇文章是SQL Server安全系列的第四篇,详细内容请参考原文. 权限授予主体访问对象,以执行某些操作.SQL Server有大量你可以授予给主体的权限,你甚至可以拒绝或回收权限.这听起来有点复杂 ...

  10. ES6 基础

    转载自:ES6 基础 一.新的变量声明方式 let/const 与var不同,新的变量声明方式带来了一些不一样的特性,其中最重要的两个特性就是提供了块级作用域与不再具备变量提升. 通过2个简单的例子来 ...