hdoj 5033 凸包
来源:互联网 发布:nginx linux内核优化 编辑:程序博客网 时间:2024/05/19 16:33
hdoj 5033
题意:若干高楼, 一个人站中间,问他看到蓝天的最大角度,或者说是左边看到的和右边看到的大楼的仰角和的补角。
思路:
三条黑线代表高楼,分别表示1号、2号、3号高楼,红点和黄点是人所在的地点。
当人在红点时,显然左边所有楼中3号楼仰角最大,但是到黄点的时候,2号楼仰角最大,这时就可以删掉3号楼,因为黄点右边的点也不会被3号楼挡住;考虑如果1号楼之前有更高的楼层,黄点的仰角可以更大的话,那么1、2、3号楼都会被删掉。
所以这个问题就转化成了一个求凸包的问题,两边分别求凸包就可以得到询问点左右最大的仰角。
#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>using namespace std;struct Point { double x, h; int id; void input() { scanf("%lf %lf", &x, &h); } Point(){} Point(int a, int b): x(a), h(b){} bool operator < (const Point &i) const { return x < i.x; }};Point point[200020], stk[200020];double ans[100020];long long gradjudge(Point a, Point b, Point c) { long long t1 = (a.x - b.x) * (c.h - b.h); long long t2 = (a.h - b.h) * (c.x - b.x); return t1 - t2;}const double PI = acos(-1.0);main() { int t, n, nq; scanf("%d", &t); for(int cas = 1; cas <= t; cas++) { memset(ans, 0, sizeof ans); scanf("%d", &n); for(int i = 1; i <= n; i++) point[i].input(); scanf("%d", &nq); for(int i = 1; i <= nq; i++) scanf("%lf", &point[i + n].x), point[i + n].h = 0, point[i + n].id = i; n = n + nq; sort(point + 1, point + n + 1); int k = 0; for(int i = 1; i <= n; i++) { while(k > 1 && gradjudge(stk[k - 2], stk[k - 1], point[i]) <= 0) k--; if(point[i].h == 0) { ans[point[i].id] += atan((point[i].x - stk[k - 1].x) / stk[k - 1].h); // printf("%f %f %f\n", stk[k - 1].h, point[i].x - stk[k - 1].x, ans[point[i].id]); } stk[k++] = point[i]; } k = 0; for(int i = n; i >= 1; i--) { while(k > 1 && gradjudge(stk[k - 2], stk[k - 1], point[i]) >= 0) k--; if(point[i].h == 0) { ans[point[i].id] += atan((-point[i].x + stk[k - 1].x) / (stk[k - 1].h)); // printf("%f %f %f\n", stk[k - 1].h, -point[i].x + stk[k - 1].x, ans[point[i].id]); } stk[k++] = point[i]; } printf("Case #%d:\n", cas); for(int i = 1; i <= nq; i++){ printf("%.10f\n", ans[i] / PI * 180.0); } }}
0 0
- hdoj 5033 凸包
- HDOJ 1348 Wall 凸包
- HDOJ 1348 Wall (凸包)
- HDOJ 1348 Wall (凸包)
- hdoj 2202 最大三角形 (凸包)
- HDOJ 1348 基本二维凸包问题
- HDOJ 1348 Wall (凸包模板题)
- HDOJ 1392 Surround the Trees (凸包)
- hdoj Wall 1348 (凸包)
- HDOJ 4946 Area of Mushroom(凸包)
- 【凸包】 HDOJ 4978 A simple probability problem.
- 【凸包+模拟退火】 HDOJ 2440 Watch out the Animal
- HDOJ 2108 Shape of HDU(凸包问题)
- hdoj Surround the Trees 1392 (凸包)
- HDOJ 1392 Surround the Trees【凸包周长 Graham扫描】
- HDOJ 5533 Dancing Stars on Me(凸包,convex hall)
- HDOJ题目1392Surround the Trees(数学几何,凸包模板)
- 杭电OJ(HDOJ)1392题:Surround the Trees(凸包问题)
- socket select模型编程
- rest实战
- svn linux命令
- 南邮 OJ 1913 闹钟
- JavaScript中setInterval函数应用常见问题之一(第一个参数不加引号与加引号的区别)
- hdoj 5033 凸包
- Handler、Looper、MessageQueue(三)
- DevExpress v15.1:TestCafe功能升级
- 拓扑排序(topological sort)DFS
- 南邮 OJ 1914 小明与小红
- linux下的NetworkManager服务,解决service network restart 闲置网卡报错问题
- Oracle VM VirtualBox VBoxDD.Dll GetLastError=1790 错误处理方法
- Linux系统命令及Shell脚本学习笔记一:Linux简介
- MySQL触发器、存储过程、自定义函数、视图 常用SQL