#pragma warning (disable:4996)
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#define maxn 150
using namespace std; int n;
struct Segment
{
double l, r, x;
int li, ri;
bool isleft;
bool operator < (const Segment &b) const{
return x < b.x;
}
}s[maxn*3]; int top;
double ydis[800];
int ytop = 0; struct Node
{
int cov;
int l, r;
double len;
}N[3000]; void build(int i, int L, int R)
{
N[i].cov = 0;
N[i].l = L; N[i].r = R;
N[i].len = ydis[R] - ydis[L];
if (N[i].r-N[i].l<=1){
return;
}
int M = (L + R) >> 1;
build(i << 1, L, M);
build(i << 1 | 1, M, R);
} void pushDown(int i)
{
if (N[i].r-N[i].l<=1) return;
if (N[i].cov!=0){
N[i << 1].cov += N[i].cov;
N[i << 1 | 1].cov += N[i].cov;
N[i].cov = 0;
}
} void add(int i, int L, int R,int val)
{
if (N[i].l == L&&N[i].r == R){
N[i].cov += val;
return;
}
pushDown(i);
int M = (N[i].l + N[i].r) >> 1;
if (R <= M) add(i << 1, L, R, val);
else if (L >= M) add(i << 1 | 1, L, R, val);
else {
add(i << 1, L, M, val);
add(i << 1 | 1, M, R, val);
}
} double query(int i)
{
pushDown(i);
if (N[i].r - N[i].l <= 1&&N[i].cov>0) return N[i].len;
else if (N[i].r - N[i].l <= 1) return 0;
return query(i << 1) + query(i << 1 | 1);
} int main()
{
int ca = 0;
while (cin >> n&&n)
{
double x1, y1, x2, y2; top = 0; ytop = 0;
for (int i = 0; i < n; i++){
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
s[top].x = x1; s[top].l = y1; s[top].r = y2; s[top++].isleft = true;
s[top].x = x2; s[top].l = y1; s[top].r = y2; s[top++].isleft = false;
ydis[ytop++] = y1; ydis[ytop++] = y2;
}
sort(ydis, ydis + ytop);
ytop = unique(ydis, ydis + ytop) - ydis;
sort(s, s + top);
for (int i = 0; i < top; i++){
s[i].li = lower_bound(ydis, ydis + ytop, s[i].l) - ydis;
s[i].ri = lower_bound(ydis, ydis + ytop, s[i].r) - ydis;
}
ydis[ytop] = ydis[ytop - 1];
build(1, 0, ytop); double ans = 0;double lx = s[0].x;
for (int i = 0; i < top; i++){
ans += query(1)*(s[i].x - lx);
if (s[i].isleft){
add(1, s[i].li, s[i].ri ,1);
}
else{
add(1, s[i].li, s[i].ri, -1);
}
lx = s[i].x;
}
printf("Test case #%d\n", ++ca);
printf("Total explored area: %.2lf\n", ans);
puts("");
}
return 0;
}

HDU1542 Atlantis(矩形面积并)的更多相关文章

  1. hdu1542 Atlantis(矩阵面积的并)

    这个题算是我的第一个扫描线的题,扫描线算是一种思想吧,用到线段树+离散化.感觉高大上. 主要参考了这位大神的博客. http://www.cnblogs.com/kuangbin/archive/20 ...

  2. 【HDU 1542】Atlantis 矩形面积并(线段树,扫描法)

    [题目] Atlantis Problem Description There are several ancient Greek texts that contain descriptions of ...

  3. HDU1542 扫描线(矩形面积并)

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

  4. (HDU 1542) Atlantis 矩形面积并——扫描线

    n个矩形,可以重叠,求面积并. n<=100: 暴力模拟扫描线.模拟赛大水题.(n^2) 甚至网上一种“分块”:分成n^2块,每一块看是否属于一个矩形. 甚至这个题就可以这么做. n<=1 ...

  5. POJ 1151 Atlantis 矩形面积求交/线段树扫描线

    Atlantis 题目连接 http://poj.org/problem?id=1151 Description here are several ancient Greek texts that c ...

  6. POJ-1151 Atlantis 矩形面积并

    题目链接:http://poj.org/problem?id=1151 扫描线+离散+线段树,线段树每个节点保存的是离散后节点右边的线段. //STATUS:C++_AC_16MS_208KB #in ...

  7. poj1151 Atlantis && cdoj 1600艾尔大停电 矩形面积并

    题目: Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23758   Accepted: 8834 Des ...

  8. hdu 1542&&poj 1151 Atlantis[线段树+扫描线求矩形面积的并]

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

  9. HDU 1542"Atlantis"(线段树+扫描线求矩形面积并)

    传送门 •题意 给你 n 矩形,每个矩形给出你 $(x_1,y_1),(x_2,y_2)$ 分别表示这个矩形的左下角和右上角坐标: 让你求这 n 个矩形并的面积: 其中 $x \leq 10^{5} ...

随机推荐

  1. SRF之数据访问

    数据访问组件实现实体类和数据表映射.SQL语句配置执行.动态sql语句等功能,ORM方式能实现简单的对象和表的映射(配置类似hibernate),但比较单一(不支持一对多.多对多的情况),下边不做介绍 ...

  2. <bootstrap>bs2和3的区别</bootstrap>

    实验室的list网站开始动工了,准备打算用bootstrap作布局. 大前天去本部停了长html5峰会大连站的讲演,着急往回赶,很多感兴趣的东西都没有听到,但是还是了解了一些html5的新特性 电脑端 ...

  3. 菜鸟学习Spring——初识Spring

    一.概念. Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One J2EE Develop ...

  4. 菜鸟学习Hibernate——多对多关系映射

    Hibernate中的关系映射,最常见的关系映射之一就是多对多关系映射例如用户与角色的关系,一个用户对应多个角色,一个角色对应多个用户.如图: Hibernate中如何来映射这两个的关系呢? 下面就为 ...

  5. .net 的生成操作

    生成操作(BuildAction) 属性:BuildAction 属性指示 Visual Studio .NET 在执行生成时对文件执行的操作. BuildAction 可以具有以下几个值之一: 无( ...

  6. Swift function how to return nil

    这两天在学习Stanford出品的iOS7的课程,这个课程去年也看过,但是看到第3课就不行了,满篇的OC,把人都搞晕了.这段时间因为要写个iOS的App,正好赶上了Swift问世,所以趁着这股劲继续学 ...

  7. HashSet<T>类

    HashSet<T>类主要是设计用来做高性能集运算的,例如对两个集合求交集.并集.差集等.集合中包含一组不重复出现且无特性顺序的元素. HashSet<T>的一些特性如下: 1 ...

  8. Android编程: 界面组成、事件监听器

    学习知识:界面组成.事件监听器 ====界面组成==== 1.用户界面的基本组件叫做View,都是继承android.view.View类,Android里面预定义很多基本的界面组件,比如 Butto ...

  9. 3. 戏说VHDL之入门游戏一:流水灯

    一.   流水灯 1.1流水灯原理 流水灯是每个学电子的入门“游戏” ,示意图如图1,其原理极其简单,但是可玩性却极强,可以就8个LED写出不同花样的程序.在1.2中我们列出两个不同思路的代码作为VH ...

  10. xml之Schema架构

    1.什么是Schema架构 2.Schema文档结构  3.Schema元素类型 1>element元素 <!--简单数据:类型--> <xs:element name=&qu ...