HDU 1542 Atlantis(线段树扫描线,面积并)
来源:互联网 发布:湖南省网络交易监管网 编辑:程序博客网 时间:2024/05/16 14:49
题意:
给你
n (n<=100) 个矩阵,问你矩阵并后的面积。
解析:
http://www.cnblogs.com/kane0526/archive/2013/02/26/2934214.html
参考了这篇题解报告,终于学会了基本的线段树扫描线。
#include <cstdio>#include <cstring>#include <algorithm>#define ls o<<1#define rs o<<1|1#define lson ls, L, M#define rson rs, M+1, Rusing namespace std;const int INF = 0x3f3f3f3f;const int maxn = 205;double X[maxn];int n, m, tot;struct Line { double l, r, h; int d; Line() {} Line(double x1, double x2, double h, int d) : l(x1), r(x2), h(h), d(d) {} bool operator < (const Line& rhs) const { return h < rhs.h; }} line[maxn];double sumv[maxn<<2];int cover[maxn<<2];inline void pushUp(int o, int L, int R) { if(cover[o]) sumv[o] = X[R+1] - X[L]; else if(L == R) sumv[o] = 0; else sumv[o] = sumv[ls] + sumv[rs];}void build(int o, int L, int R) { sumv[o] = cover[o] = 0; if(L == R) return ; int M = (L + R)/2; build(lson); build(rson);}void modify(int o, int L, int R, int ql, int qr, int d) { if(ql <= L && R <= qr) { cover[o] += d; pushUp(o, L, R); return ; } int M = (L + R)/2; if(ql <= M) modify(lson, ql, qr, d); if(qr > M) modify(rson, ql, qr, d); pushUp(o, L, R);}int main() { double x1, y1, x2, y2; int cas = 1; while(~scanf("%d", &n) && n) { m = tot = 0; for(int i = 0; i < n; i++) { scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2); line[m] = Line(x1, x2, y1, 1); X[m++] = x1; line[m] = Line(x1, x2, y2, -1); X[m++] = x2; } //discrete sort(X, X+m); tot = unique(X, X+m) - X; sort(line, line+m); build(1, 0, tot-1); int ql, qr; double ans = 0; for(int i = 0; i < m; i++) { ql = lower_bound(X, X+tot, line[i].l) - X; qr = lower_bound(X, X+tot, line[i].r) - X - 1; modify(1, 0, tot-1, ql, qr, line[i].d); ans += sumv[1] * (line[i+1].h - line[i].h); } printf("Test case #%d\n", cas++); printf("Total explored area: %.2lf\n\n", ans); } return 0;}
0 0
- HDU 1542 Atlantis(线段树扫描线,面积并)
- hdu 1542 Atlantis 面积并 线段树 扫描线
- hdu 1542 Atlantis(线段树 面积并+扫描线)
- hdu 1542 Atlantis(线段树&扫描线&面积并)
- HDU 1542 Atlantis (线段树扫描线求面积并)
- HDU 1542 Atlantis(线段树+扫描线+面积并)
- HDU 1542 Atlantis(离散化+扫描线(求并面积)+线段树)
- HDU 1542——Atlantis(线段树+面积并+离散化+扫描线)
- hdu 1542 Atlantis(线段树进阶,扫描线,矩形面积并)
- HDU 1542 Atlantis(线段树扫描线·面积并)
- hdu 1542 Atlantis(线段树,扫描线之面积并)
- hdu 1542 Atlantis(线段树+扫描线——面积并)
- Atlantis 线段树扫描线--面积并
- HDU1542 Atlantis(扫描线+矩形面积并+线段树)
- 【扫描线】 HDU 1542 Atlantis 面积并
- poj 1151 hdu 1542 hoj1119 Atlantis 线段树扫描线求矩形面积并
- poj 1151 Atlantis / hdu 1542 线段树扫描线 矩形面积并
- POJ1151 (HDU 1542) Atlantis【矩形面积并,线段树+离散化+扫描线模板】
- 数据结构中排序方法基本概念 及 分类
- 黑马程序员——IDE&Object类、常用API-String类、常用API-Arrays、System、StringBuffer&Integer类和Date类、对象数组
- poj1734Sightseeing trip floyd最小环
- 汤姆猫实现代码
- Lowest Common Ancestor of a Binary Tree
- HDU 1542 Atlantis(线段树扫描线,面积并)
- Alex / OverFeat / VGG 中的卷积参数
- 三种东西永远不要放到数据库里
- mongoDB 3.0 安全权限访问控制
- Linux下如何查看系统启动时间和运行时间
- 深入理解开源数据库中间件 Vitess:核心特性以及如何进行数据存储的堆叠
- python 模块
- HDU 5412 CRB and Queries(区间第K大 树套树 按值建树)
- Cocos2d-x 之 八方向小摇杆