#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. HelloWorld IL代码

    .assembly extern mscorlib .assembly HelloWorld.class HelloWorld extends [mscorlib] System.Object {   ...

  2. Node.js学习笔记 01 搭建静态服务器

    希望这篇文章能解决你这样一个问题:“我现在已经了解了一些Node.Js基本概念了,怎么搭一台静态服务器呢?” 请参考一下博主的前两篇文章: 完全面向于初学者的Node.js指南 Node.Js的Mod ...

  3. uva 11538 Chess Queen<计数>

    链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...

  4. 菜鸟学习Spring——60s配置XML方法实现简单AOP

    一.概述. 上一篇博客讲述了用注解的形式实现AOP现在讲述另外一种AOP实现的方式利用XML来实现AOP. 二.代码演示. 准备工作参照上一篇博客<菜鸟学习Spring--60s使用annota ...

  5. android-监听网络状态

    1.注册一个广播接收器,监听网络状态private void Start() { IntentFilter filter = new IntentFilter(); filter.addAction( ...

  6. php之常用函数库

    1.时间和日期 如何获取时间戳 time()--从1970年开始计算的毫秒数 echo time(); 日期 echo date('Y-m-d H:i:s'); 获取默认是时区 echo date_d ...

  7. 如何让webapi只返回json格式数据

    最近脑子不好用,总记不住事,以前搞过让webapi只返回json格式的数据,今天有人问我又突然想不起了,后来总结一下,备忘一下,大概有下面几种处理方式 1.在WebApiConfig类的Registe ...

  8. 读:HIS 与医保系统的接入方案及实现

    HIS 与医保系统的接入方案及实现刘剑锋 李刚荣第三军医大学西南医院信息科(重庆 400038) 医院HIS和医保系统的接口设计方案涉及两个部分,分别由医院和医保中心分别完成相,应的程序设计,这两部分 ...

  9. typedef和自定义结构体类型

    在自定义结构体类型时会用到typedef关键字.大家都知道typedef是取别名的意思,在C语言中跟它容易混淆的有const,#define等,其区别不在本篇文章讨论之列. /*定义单链表结点类型*/ ...

  10. 微软职位内部推荐-SDEII

    微软近期Open的职位: Software Engineer II for Customer Experience (Level 62+) Location: Suzhou Contact Perso ...