There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of the island. But unfortunately, these maps describe different regions of Atlantis. Your friend Bill has to know the total area for which maps exist. You (unwisely) volunteered to write a program that calculates this quantity. 

InputThe input file consists of several test cases. Each test case starts with a line containing a single integer n (1<=n<=100) of available maps. The n following lines describe one map each. Each of these lines contains four numbers x1;y1;x2;y2 (0<=x1<x2<=100000;0<=y1<y2<=100000), not necessarily integers. The values (x1; y1) and (x2;y2) are the coordinates of the top-left resp. bottom-right corner of the mapped area.

The input file is terminated by a line containing a single 0. Don’t process it.OutputFor each test case, your program should output one section. The first line of each section must be “Test case #k”, where k is the number of the test case (starting with 1). The second one must be “Total explored area: a”, where a is the total explored area (i.e. the area of the union of all rectangles in this test case), printed exact to two digits to the right of the decimal point.

Output a blank line after each test case. 
Sample Input

2
10 10 20 20
15 15 25 25.5
0

Sample Output

Test case #1
Total explored area: 180.00 这题也是模板提
 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
using namespace std;
#define bug printf("******\n");
#define rtl rt<<1
#define rtr rt<<1|1
typedef long long LL;
const int maxn = 1e5 + ;
struct LINE {
double x, y1, y2;
int flag;
} line[];
int cmp(LINE a, LINE b) {
return a.x < b.x;
}
struct node {
double pre, l, r;
int cover, flag;
} tree[];
double y[];
void build(int rt, int l, int r) {
tree[rt].l = y[l], tree[rt].r = y[r];
tree[rt].flag = -, tree[rt].cover = , tree[rt].pre = -;
if (l + == r) {
tree[rt].flag = ;
return ;
}
int m = (l + r) >> ;
build(rtl, l, m);
build(rtr, m, r);
}
double query(int rt, double x, double y1, double y2, int flag) {
if (tree[rt].r <= y1 || tree[rt].l >= y2) return ;
if (tree[rt].flag == ) {
if (tree[rt].cover > ) {
double pre = tree[rt].pre;
double ans = (x - pre) * (tree[rt].r - tree[rt].l);
tree[rt].pre = x;
tree[rt].cover += flag;
return ans;
} else {
tree[rt].cover += flag;
tree[rt].pre = x;
return ;
}
}
return query(rtl, x, y1, y2, flag) + query(rtr, x, y1, y2, flag);
}
int main() {
int cas = , n;
while(scanf("%d", &n), n) {
int cnt = -;
for (int i = ; i < n ; i++) {
double x1, y1, x2, y2;
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
y[++cnt] = y1;
line[cnt].flag = ;
line[cnt].x = x1;
line[cnt].y1 = y1;
line[cnt].y2 = y2;
y[++cnt] = y2;
line[cnt].flag = -;
line[cnt].x = x2;
line[cnt].y1 = y1;
line[cnt].y2 = y2;
}
sort(y, y + cnt + );
sort(line, line + cnt + , cmp);
build(, , cnt);
double ans = ;
for (int i = ; i <= cnt ; i++ )
ans += query(, line[i].x, line[i].y1, line[i].y2, line[i].flag);
printf("Test case #%d\n", cas++);
printf("Total explored area: %.2lf\n\n", ans);
}
return ;
}

Atlantis HDU - 1542 (线段树扫描线)的更多相关文章

  1. Atlantis HDU - 1542 线段树+扫描线 求交叉图形面积

    //永远只考虑根节点的信息,说明在query时不会调用pushdown //所有操作均是成对出现,且先加后减 // #include <cstdio> #include <cstri ...

  2. hdu 1542 线段树+扫描线 学习

    学习扫描线ing... 玄学的东西... 扫描线其实就是用一条假想的线去扫描一堆矩形,借以求出他们的面积或周长(这一篇是面积,下一篇是周长) 扫描线求面积的主要思想就是对一个二维的矩形的某一维上建立一 ...

  3. HDU 1542 线段树+扫描线+离散化

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  4. hdu 1542 线段树扫描(面积)

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  5. hdu 4052 线段树扫描线、奇特处理

    Adding New Machine Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  6. hdu 1828 线段树扫描线(周长)

    Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  7. hdu 5091(线段树+扫描线)

    上海邀请赛的一道题目,看比赛时很多队伍水过去了,当时还想了好久却没有发现这题有什么水题的性质,原来是道成题. 最近学习了下线段树扫描线才发现确实是挺水的一道题. hdu5091 #include &l ...

  8. HDU 5107 线段树扫描线

    给出N个点(x,y).每一个点有一个高度h 给出M次询问.问在(x,y)范围内第k小的高度是多少,没有输出-1 (k<=10) 线段树扫描线 首先离散化Y坐标,以Y坐标建立线段树 对全部的点和询 ...

  9. hdu 1542 线段树之扫描线之面积并

    点击打开链接 题意:给你n个矩形,求它们的面积,反复的不反复计算 思路:用线段树的扫描线完毕.将X坐标离散化后,从下到上扫描矩形,进行各种处理,看代码凝视把 #include <stdio.h& ...

  10. hdu 1255(线段树 扫描线) 覆盖的面积

    http://acm.hdu.edu.cn/showproblem.php?pid=1255 典型线段树辅助扫描线,顾名思义扫描线就是相当于yy出一条直线从左到右(也可以从上到下)扫描过去,此时先将所 ...

随机推荐

  1. 【jmeter进阶之逻辑控制器】

    jmeter进阶之逻辑控制器  转载   https://www.cnblogs.com/malinalian/p/10491946.html   常用的逻辑控制器 1,循环控制器:可以设置该控制器内 ...

  2. java学习过程小问题

    一:基本的需要注意点(基础语句); package my; public class hello { public static void main(String[] args) { // TODO ...

  3. Linear Equations in Linear Algebra

    Linear System Vector Equations The Matrix Equation Solution Sets of Linear Systems Linear Indenpende ...

  4. POJ 3487 The Stable Marriage Problem(稳定婚姻问题 模版题)

    Description The stable marriage problem consists of matching members of two different sets according ...

  5. js实现滑动器效果

    最近公司在做一个项目,页面中要用到滑动器效果,我的第一反应是使用HTML5 input类型中的range类型,但马上我就否定了这个想法,因为range类型存在浏览器的兼容性问题(在主流浏览器中).但又 ...

  6. A Compatible Pair

    Description “年”是一个生活在海洋深处的怪物.每年,它都出现在陆地上,吞噬牲畜甚至是人.为了让怪物离开,人们用红色,光线和爆炸的声音填满他们的村庄,所有这些都吓跑了怪物.   小汤米有 n ...

  7. Thunder团队第二周 - Scrum会议1

    Scrum会议1 小组名称:Thunder 项目名称:爱阅app Scrum Master:王航 工作照片: 参会成员: 王航(Master):http://www.cnblogs.com/wangh ...

  8. C语言 内存分配 地址 指针 数组 参数 实例解析

    . Android源码看的鸭梨大啊, 补一下C语言基础 ... . 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/detai ...

  9. 阿里云服务器 操作实战 部署C语言开发环境(vim配置,gcc) 部署J2EE网站(jdk,tomcat)

    . 作者 :万境绝尘  转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/18964835 . 博客总结 : 设置SecureCRT ...

  10. python 抓取网上OJ试题

    学校工作需要,需架设一台内网OJ服务器,采用了开源的hustoj.试题下载了hustoj的freeprblem的xml文件.导入时出现很多错误,不知什么原因.另外要将历年noip复赛试题加上去,但苦于 ...