hdu 5033 Building 单调栈
来源:互联网 发布:vb中阶乘 编辑:程序博客网 时间:2024/06/05 18:17
第一次写的单调栈。
本题参考http://www.cnblogs.com/yuiffy/p/3984776.html
题意:
在水平的轴上,有着多个建筑物,建筑物宽度可以看做为0,高度为hi,让你求出在所给的点,所能仰望的最大角度。
AC代码:
(代码长度应该可以优化一下)
/* **********************************************Created Time: 2014-9-24 13:32:33File Name : hdu5033.cpp*********************************************** *///#pragma comment(linker, "/STACK:102400000,102400000")#include <iostream>#include <fstream>#include <cstring>#include <climits>#include <deque>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <utility>#include <sstream>#include <complex>#include <string>#include <vector>#include <cstdio>#include <bitset>#include <functional>#include <algorithm>using namespace std;typedef long long LL;const int INF = 0x3f3f3f3f;const int MAXN = 1e5+5;const double PI = acos(-1.0);struct Point{ double x, h; double k, res; int rank;}bq[2*MAXN];int n, q;double recl[MAXN], recr[MAXN]; //record k;bool cmp(Point a, Point b){ return a.x < b.x;}bool cmp2(Point a, Point b){ return a.rank < b.rank;}void solve(){ sort(bq, bq+n+q, cmp); int nq = n+q; //left to right, find the left max view; stack <Point> sta; int cot = 0; for(int i = 0;i < nq; i++) { if(bq[i].h != 0) //building { //check high while(!sta.empty()) { if(sta.top().h <= bq[i].h) sta.pop(); else break; } // if(sta.size() == 1) { Point &e = sta.top(); bq[i].k = (e.h - bq[i].h)/(e.x - bq[i].x); sta.push(bq[i]); } else if(sta.size() == 0) { bq[i].k = 0; sta.push(bq[i]); } else { double curk; while(!sta.empty()) { Point &e = sta.top(); curk = (e.h-bq[i].h)/(e.x-bq[i].x); if(curk >= e.k) sta.pop(); else break; } bq[i].k = curk; sta.push(bq[i]); } } else //Query { double curk; while(!sta.empty()) { Point &e = sta.top(); curk = (e.h-bq[i].h)/(e.x-bq[i].x); if(curk <= e.k) break; else sta.pop(); } recl[cot++] = curk; } } //right to left, find the right max view; int cot2 = cot-1; while(!sta.empty()) sta.pop(); for(int i = nq-1; i >= 0; i--) { if(bq[i].h != 0) { while(!sta.empty()) { if(bq[i].h >= sta.top().h) sta.pop(); else break; } if(sta.size() == 1) { Point &e = sta.top(); bq[i].k = (e.h-bq[i].h)/(e.x-bq[i].x); sta.push(bq[i]); } else if(sta.size() == 0) { bq[i].k = 0; sta.push(bq[i]); } else { double curk; while(!sta.empty()) { Point &e = sta.top(); curk = (e.h-bq[i].h)/(e.x-bq[i].x); if(curk <= e.k) sta.pop(); else break; } bq[i].k = curk; sta.push(bq[i]); } } else { double curk; while(!sta.empty()) { Point &e = sta.top(); curk = (e.h-bq[i].h)/(e.x-bq[i].x); if(curk > e.k) break; else sta.pop(); } recr[cot2--] = curk; } }}int main(){ int T, cas = 0; scanf("%d", &T); while(T--) { //input scanf("%d", &n); for(int i = 0;i < n; i++) { scanf("%lf%lf", &bq[i].x, &bq[i].h); bq[i].rank = i; } scanf("%d", &q); for(int i = n;i < q+n; i++) { scanf("%lf", &bq[i].x); bq[i].h = 0, bq[i].rank = i; } // // solve(); int cot = 0; for(int i = 0;i < q+n; i++) { if(bq[i].h != 0) continue; bq[i].res = 180 - atan(abs(recl[cot]))*180/PI - atan(recr[cot])*180/PI; cot++; } sort(bq, bq+n+q, cmp2); printf("Case #%d:\n", ++cas); for(int i = n;i < q+n; i++) printf("%.5lf\n", bq[i].res); } return 0;}
0 0
- HDU 5033 Building (单调栈)
- 【HDU】5033 Building 单调栈
- HDU 5033 Building (单调栈)
- hdu 5033 Building 单调栈
- hdu 5033 Building(单调栈)
- hdu 5033 ( Building ) 单调栈
- hdu 5033 Building 几何+单调栈
- HDU 5033 - Building(几何 + 单调栈)
- HDU - 5033 Building(单调栈)
- hdu - 5033 - Building(单调栈)
- HDU 5033 Building(单调栈, 类凸包)
- HDU 5033 Building --离线+单调栈
- HDU 5033 Building 单调队列
- HDU 5033-B - Building-维护凸包-单调栈
- HDU 5033 Building (单调栈维护凸包)
- HDU 5033 Building (单调栈、计算几何)
- HDU 5033 Building(2014北京网络赛 单调栈+几何)
- HDU 5033 Building 单调栈 2014网络赛北京站B题
- Lucene的多域查询、结果中查询、查询结果分页、高亮查询结果和结果评分
- android解析json
- python 发邮件。。。
- [解决]打开tomcat-6.0.18的startup.bat后,DOS窗口一闪就关闭了
- 利用反射实现简单的Spring注解注入实例
- hdu 5033 Building 单调栈
- 互动出版网APP
- 计算text的size
- MySql创建hive用户,并赋予权限
- Lucene介绍:Query
- appium+java+ios自动化环境的搭建部分代码,资料的搜集与整合。
- git format-patch的使用
- JQuery 跨框架(iframe)操作
- 什么是固件以及OpenWrt