HDU 5033 Building(模拟凸包建立过程)
来源:互联网 发布:软件开发全面质量管理 编辑:程序博客网 时间:2024/04/29 16:17
题目链接:
传送门
题意:
在坐标轴上有n个点,每个点的有一个建筑物,高度为h,求一个人站在坐标为
分析:
我们将询问的点
Code
#include <bits/stdc++.h>using namespace std;const int maxn = 2e5+10;const double eps = 1e-10;const double pi = acos(-1.0);int dcmp(double x) { if(fabs(x)<eps) return 0; else return x < 0 ? -1 : 1;}struct Point { double x, y; int id; double thea1,thea2; bool operator < (const Point& a) const { return x < a.x; } bool operator == (const Point B)const { return dcmp(x-B.x)==0&&dcmp(y-B.y)==0; }} p[maxn],st[maxn];double calc(Point a,Point b){ return (b.y-a.y)/fabs(b.x-a.x);}bool cmp(const Point &A,const Point &B){ return A.id<B.id;}int main(){ int t,n,m,cas=1; scanf("%d",&t); while(t--){ scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%lf%lf%",&p[i].x,&p[i].y); p[i].id=i; } scanf("%d",&m); for(int i=n;i<n+m;i++){ scanf("%lf",&p[i].x); p[i].id=i; p[i].y=0; } n+=m; sort(p,p+n); int top=0; st[0]=p[0]; for(int i=1;i<n;i++){ if(p[i].id<n-m){ while(top&&calc(p[i],st[top])<calc(st[top],st[top-1])){ top--; } st[++top]=p[i]; } else{ int tmp = top; while(tmp&&calc(p[i],st[tmp])<calc(p[i],st[tmp-1])) tmp--; p[i].thea1=calc(p[i],st[tmp]); } } top=0; st[0]=p[n-1]; for(int i=n-2;i>=0;i--){ if(p[i].id<n-m){ while(top&&calc(p[i],st[top])<calc(st[top],st[top-1])) top--; st[++top]=p[i]; } else{ int tmp = top; while(tmp&&calc(p[i],st[tmp])<calc(p[i],st[tmp-1])) tmp--; p[i].thea2=calc(p[i],st[tmp]); } } sort(p,p+n,cmp); printf("Case #%d:\n",cas++); for(int i=n-m;i<n;i++){ double thea = pi - atan(p[i].thea1)-atan(p[i].thea2); printf("%.5lf%c",thea*180.0/pi,i==n-1 ? '\n' : ' '); } } return 0;}
1 0
- HDU 5033 Building(模拟凸包建立过程)
- Building Fence hdu 凸包
- HDU 5033 Building 解题报告(维护凸包)
- HDU 5033-B - Building-维护凸包-单调栈
- HDU 5033 Building (单调栈维护凸包)
- HDU 5191 Building Blocks (模拟)
- hdu 4667 Building Fence(二维凸包 Graham)
- HDU 4449 Building Design 三维凸包+空间坐标变换
- hdu5033 Building 凸包
- HDU 5538 House Building (简单模拟)
- hdu 5191 Building Blocks(模拟,思路)
- HDU 5033 Building
- HDU - 5033 Building
- hdu-5033-Building
- HDU 5033 - Building
- hdu 5033 Building
- hdu 5033 Building
- hdu 5033 Building
- Spring Cache缓存介绍
- 黑马程序员——Java基础---集合类(上)
- HDU_5463 Clarke and minecraft
- json jar 包的几种字符串转换
- 配置tftp服务以及开发板中通过tftp下载文件
- HDU 5033 Building(模拟凸包建立过程)
- HDU 4296 Buildings
- Java设计模式 —— 开篇
- Oracle数据库新创建实例会遇到的有关监听的问题
- 软件内存泄露的原因
- Kotlin学习笔记(二)——示例篇一
- 区间最小值
- c++在vs2010中操作Mysql的讲解
- Oracle spatial创建空间数据的字段详解