Atlantis

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10208    Accepted Submission(s): 4351

Problem Description
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.
 
Input
The 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.

 
Output
For 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
/*
hdu 1542 线段树扫描(面积) 给你n个矩形,求最终形成的图形的面积大小 数据不一定是整数,所以先对他们进行离散化处理
大致就是每次计算平行于x轴的两条相邻线之间的面积,我们已经知道了两条平行
线之间的高度,于是就转变成在求当前情况下映射到x轴上的线段的长度,这个便能
利用线段树解决了 先把所有平行于x轴的线段按高度排序,然后从下往上,每次在遇到矩形下边时在
[l,r]上加1表示线段覆盖,遇到上边则填上-1消除影响.然后每次计算覆盖长度
再乘上高即可 参考(图文详解):
http://www.cnblogs.com/scau20110726/archive/2013/04/12/3016765.html hhh-2016-03-26 17:58:50
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <functional>
using namespace std;
#define lson (i<<1)
#define rson ((i<<1)|1)
typedef long long ll;
const int maxn = 10005;
double hs[maxn];
struct node
{
int l,r;
double len;
int sum;
int mid()
{
return (l+r)>>1;
}
} tree[maxn*5]; void push_up(int i)
{
if(tree[i].sum)
{
tree[i].len = (hs[tree[i].r+1]-hs[tree[i].l]);
}
else if(tree[i].l == tree[i].r)
{
tree[i].len= 0;
}
else
{
tree[i].len = tree[lson].len+tree[rson].len;
}
} void build(int i,int l,int r)
{
tree[i].l = l;
tree[i].r = r;
tree[i].sum = tree[i].len = 0;
if(l == r)
return ; int mid = tree[i].mid();
build(lson,l,mid);
build(rson,mid+1,r);
push_up(i);
} void push_down(int i)
{ } void Insert(int i,int l,int r,int val)
{
if(tree[i].l >= l && tree[i].r <=r )
{
tree[i].sum += val;
push_up(i);
return ;
}
int mid = tree[i].mid();
push_down(i);
if(l <= mid)
Insert(lson,l,r,val);
if(r > mid)
Insert(rson,l,r,val);
push_up(i);
} struct edge
{
double l,r,high;
int va;
edge() {};
edge(double _l,double _r,double _high,int _va):l(_l),r(_r),high(_high),va(_va)
{}
};
edge tx[maxn*2]; bool cmp(edge a,edge b)
{
if(a.high != b.high)
return a.high < b.high;
else
return a.va > b.va;
}
int tot,m;
int fin(double x)
{
int l = 0,r = m-1;
while(l <= r)
{
int mid = (l+r)>>1;
if(hs[mid] == x)
return mid;
else if(hs[mid] < x)
l = mid+1;
else
r = mid-1;
}
} int main()
{
int n;
int cas =1;
while(scanf("%d",&n) != EOF && n)
{
double x1,x2,y1,y2;
tot = 0;
for(int i = 1; i <= n; i++)
{
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
hs[tot] = x1;
tx[tot++] = edge(x1,x2,y1,1);
hs[tot] = x2;
tx[tot++] = edge(x1,x2,y2,-1);
}
sort(tx,tx+tot,cmp);
sort(hs,hs+tot);
m = 1;
for(int i = 1;i < tot;i++)
{
if(hs[i] != hs[i-1])
hs[m++] = hs[i];
}
build(1,0,m);
double ans = 0;
for(int i = 0;i < tot;i++)
{
int l = fin(tx[i].l);
int r = fin(tx[i].r)-1; Insert(1,l,r,tx[i].va);
ans += (tree[1].len)*(tx[i+1].high-tx[i].high);
//cout << ans <<endl;
}
printf("Test case #%d\n",cas++);
printf("Total explored area: %.2f\n\n",ans);
}
return 0;
}

  

												

hdu 1542 线段树扫描(面积)的更多相关文章

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

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

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

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

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

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

  4. HDU 1542 线段树离散化+扫描线 平面面积计算

    也是很久之前的题目,一直没做 做完之后觉得基本的离散化和扫描线还是不难的,由于本题要离散x点的坐标,最后要计算被覆盖的x轴上的长度,所以不能用普通的建树法,建树建到r-l==1的时候就停止,表示某段而 ...

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

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

  6. hdu 1542 线段树 求矩形并

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

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

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

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

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

  9. hdu 4533 线段树(问题转化+)

    威威猫系列故事——晒被子 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Tot ...

随机推荐

  1. 项目Beta冲刺Day3

    项目进展 李明皇 今天解决的进度 完善了程序的运行逻辑(消息提示框等) 明天安排 前后端联动调试 林翔 今天解决的进度 向微信官方申请登录验证session以维护登录态 明天安排 继续完成维护登录态 ...

  2. hdu 5274 Dylans loves tree

    Dylans loves tree http://acm.hdu.edu.cn/showproblem.php?pid=5274 Time Limit: 2000/1000 MS (Java/Othe ...

  3. VMware虚拟机误删除vmdk文件后如何恢复?

    故障描述: Dell R710系列服务器(用于VMware虚拟主机),Dell MD 3200系列存储(用于存放虚拟机文件),VMware ESXi 5.5版本,因意外断电,导致某台虚拟机不能正常启动 ...

  4. aix 6.1系统怎么安装?这里有详细图文教程

    今年六月,我们公司出现了一次非常严重的数据丢失的事故.生产服务器崩溃导致所有的业务都陷于停滞,而且由于涉及到公司机密又无法贸然到数据恢复公司进行恢复,可是自己又无法解决.权衡利弊还是决定找一家有保密资 ...

  5. vue class与style 绑定详解——小白速会

    一.绑定class的几种方式 1.对象语法 直接看例子: <div id="app3"> <div :class="{'success':isSucce ...

  6. signalR 消息推送

    业务情景一:上传报表,上传excel.如果excel的数据量很大,上万条,上十万条数据,那么这个上传请求必然是个耗时请求.用户上传之后,很关心上传的进度和结果. 业务情景二:站内消息提醒,实时有效地接 ...

  7. python 字符串和字典

    一.字符串操作 name = "my name is \t {name} and i am {year} years old" 1.首字母大写 print(name.capital ...

  8. linux下面根据不同的日期创建不同文件,一般用户数据库的备份的shell编程

    [root@www scripts]# vi sh03.sh #!/bin/bash # Program: #  Program creates three files, which named by ...

  9. 【转】支持向量机(SVM)

    什么是支持向量机(SVM)? SVM 是一种有监督的机器学习算法,可用于分类或回归问题.它使用一种称为核函数(kernel)的技术来变换数据,然后基于这种变换,算法找到预测可能的两种分类之间的最佳边界 ...

  10. win-zabbix_agent端配置解析

    Zabbix agent 在windows上安装部署 部署windows服务器需要在agent服务器上添加到10.4.200.2的路由 蓝泰服务器需要添加10.0.90.5的网关,联通的机器需要添加到 ...