HDOJ-1542 Atlantis(扫描线)
来源:互联网 发布:网络教育好找工作吗 编辑:程序博客网 时间:2024/06/08 08:25
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define maxn 105using namespace std;struct Node{ Node(){ } Node(double a, double b, double c, int d){ x1 = a; x2 = b; y = c; flag = d; } double x1, x2, y; int flag; friend bool operator < (const Node &a, const Node &b){ return a.y < b.y; }}node[maxn];double sum[maxn<<3], p[maxn<<1];int cnt[maxn<<3];void Pushup(int n, int l, int r){ if(cnt[n]) sum[n] = p[r+1] - p[l]; else if(l == r) sum[n] = 0; else sum[n] = sum[n<<1] + sum[n<<1|1];}void Update(int n, int l, int r, int L, int R, int s){ if(l == L && R == r){ cnt[n] += s; Pushup(n, l, r); return ; } int mid = (l + r) >> 1; if(R <= mid) Update(n<<1, l, mid, L, R, s); else if(L > mid) Update(n<<1|1, mid+1, r, L, R, s); else{ Update(n<<1, l, mid, L, mid, s); Update(n<<1|1, mid+1, r, mid+1, R, s); } Pushup(n, l, r);}int main(){// freopen("in.txt", "r", stdin); int n, t = 0; while(scanf("%d", &n) == 1 && n){ memset(sum, 0, sizeof(sum)); memset(cnt, 0, sizeof(cnt)); double x1, y1, x2, y2; int k = 0; for(int i= 1; i <= n; i++){ scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2); node[2*i-1] = Node(x1, x2, y1, 1); node[2*i] = Node(x1, x2, y2, -1); p[++k] = x1; p[++k] = x2; } sort(node+1, node+1+2*n); sort(p+1, p+1+k); int d = unique(p+1, p+1+k) - p - 1; double ss = 0; for(int i = 1; i < 2*n; i++){ int l = lower_bound(p+1, p+1+d, node[i].x1) - p; int r = lower_bound(p+1, p+1+d, node[i].x2) - p; Update(1, 1, d, l, r - 1, node[i].flag); ss += sum[1] * (node[i+1].y - node[i].y); } printf("Test case #%d\nTotal explored area: %.2lf\n\n", ++t, ss); } return 0;}
0 0
- HDOJ-1542 Atlantis(扫描线)
- 【线段树+扫描线】 HDOJ 1542 Atlantis
- Atlantis - HDU 1542 扫描线
- hdu 1542 Atlantis(扫描线)
- hdu 1542 Atlantis(扫描线)
- HDU 1542 Atlantis 扫描线
- POJ题目 1151|| HDOJ 题目1542Atlantis(线段树+离散化+扫描线)
- HDOJ 1542 (POJ 1151) Atlantis 【线段树 离散化 扫描线 面积并】
- hdu 1542 Atlantis 线段树扫描线
- HDU 1542 Atlantis (离散化+扫描线)
- HDU 1542 Atlantis(线段树:扫描线)
- 【HDU】1542 Atlantis 线段树+扫描线
- HDU 1542 Atlantis(线段树扫描线)
- POJ 1151 HDU 1542 Atlantis(扫描线)
- hdu 1542 Atlantis(线段树+扫描线)
- 【扫描线】 HDU 1542 Atlantis 面积并
- hdu 1542 Atlantis 线段树 + 扫描线
- HDU 1542 Atlantis 线段树+扫描线
- 论文word编辑教训
- ViewPager加小圆点无限轮播
- PriorityQueue示例
- 一个操作系统的实现(5)-关于特权级
- ubuntu15.04下broadcom无线驱动安装
- HDOJ-1542 Atlantis(扫描线)
- 教你改变UITextFiled的placeholder颜色
- 从病毒到AU3编程语言
- CSS3中clip属性
- webView 实现 与 javascript调用java方法(也称js调用native 方法) helloworld
- 动态规划算法学习
- 第12周项目3—数组类运算的实现
- sas:利用SQL连接表
- html学习笔记(一)