Atlantis

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

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
 
Source
 
Recommend
linle
 

Statistic | Submit | Discuss | Note

注意只要给一维离散化,且离散化的那一维必然是左闭右开的。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define ls (x<<1)
#define rs (ls|1)
#define lson ls,L,mid
#define rson rs,mid+1,R
#define rep(i,l,r) for (int i=l; i<=r; i++)
using namespace std; const int N=;
int n,cnt,T,tot,cov[N<<];
double x1,y1,x2,y2,ans,b[N],len[N<<];
struct P{ double x,y1,y2; int k; }p[N]; bool cmp(P &a,P &b){ return a.x<b.x; } void upd(int x,int L,int R){
if (cov[x]) len[x]=b[R+]-b[L];
else if (L==R) len[x]=; else len[x]=len[ls]+len[rs];
} void mdf(int x,int L,int R,int l,int r,int k){
if (L==l && r==R){ cov[x]+=k; upd(x,L,R); return; }
int mid=(L+R)>>;
if (r<=mid) mdf(lson,l,r,k);
else if (l>mid) mdf(rson,l,r,k);
else mdf(lson,l,mid,k),mdf(rson,mid+,r,k);
upd(x,L,R);
} int main(){
while (scanf("%d",&n),n){
T++; cnt=tot=ans=;
memset(len,,sizeof(len)); memset(cov,,sizeof(cov));
rep(i,,n){
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
p[++cnt]=(P){x1,y1,y2,}; p[++cnt]=(P){x2,y1,y2,-};
b[++tot]=y1; b[++tot]=y2;
}
sort(b+,b+tot+); tot=unique(b+,b+tot+)-b-;
sort(p+,p+cnt+,cmp);
rep(i,,cnt-)
mdf(,,tot,lower_bound(b+,b+tot+,p[i].y1)-b,lower_bound(b+,b+tot+,p[i].y2)-b-,p[i].k),ans+=len[]*(p[i+].x-p[i].x);
printf("Test case #%d\nTotal explored area: %.2lf\n\n",T,ans);
}
return ;
}

[HDU1542]Atlantis(扫描线+线段树)的更多相关文章

  1. hdu1542 Atlantis (线段树+扫描线+离散化)

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

  2. [POJ1151][HDU1542]Atlantis(线段树,扫描线)

    英文题面,我就只放个传送门了. Solution  题意是算矩形面积并,这是扫描线算法能解决的经典问题. 算法的大致思想是,把每一个矩形拆成上边和下边(以下称作扫描线),每条扫描线有四个参数l,r,h ...

  3. hdu-1542 Atlantis(离散化+线段树+扫描线算法)

    题目链接: Atlantis Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others) ...

  4. poj1151 Atlantis——扫描线+线段树

    题目:http://poj.org/problem?id=1151 经典的扫描线问题: 可以用线段树的每个点代表横向被矩形上下边分割开的每一格,这样将一个矩形的出现或消失化为线段树上的单点修改: 每个 ...

  5. POJ 1151 Atlantis (扫描线+线段树)

    题目链接:http://poj.org/problem?id=1151 题意是平面上给你n个矩形,让你求矩形的面积并. 首先学一下什么是扫描线:http://www.cnblogs.com/scau2 ...

  6. hdu1542 Atlantis(扫描线+线段树+离散)矩形相交面积

    题目链接:点击打开链接 题目描写叙述:给定一些矩形,求这些矩形的总面积.假设有重叠.仅仅算一次 解题思路:扫描线+线段树+离散(代码从上往下扫描) 代码: #include<cstdio> ...

  7. 【POJ1151】Atlantis(线段树,扫描线)

    [POJ1151]Atlantis(线段树,扫描线) 题面 Vjudge 题解 学一学扫描线 其实很简单啦 这道题目要求的就是若干矩形的面积和 把扫描线平行于某个轴扫过去(我选的平行\(y\)轴扫) ...

  8. Atlantis poj1151 线段树扫描线

    Atlantis poj1151 线段树扫描线 题意 题目给了n个矩形,每个矩形给了左下角和右上角的坐标,矩形可能会重叠,求的是矩形最后的面积. 题解思路 这个是我线段树扫描线的第一题,听了学长的讲解 ...

  9. HDU 3642 - Get The Treasury - [加强版扫描线+线段树]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Others) Memory L ...

随机推荐

  1. 【比赛】洛谷夏令营NOIP模拟赛

    Day1 第一题 水题 第二题 题意:一个n*m的字符矩阵从左上到右下,经过字符形成回文串的路径数.n≤500 回文串,考虑两段往中间DP. f[k][x][y]表示走了k步,左上点横坐标为x,右下点 ...

  2. 牛客网刷题(纯java题型 31~60题)

    牛客网刷题(纯java题型 31~60题) 重写Override应该满足"三同一大一小"三同:方法名相同,参数列表相同,返回值相同或者子类的返回值是父类的子类(这一点是经过验证的) ...

  3. java===java基础学习(1)---数据类型,运算,变量,常量

    今天起开始了java的学习之路,主要学习了数据类型和运算,变量,常量.基本和python有很多相通的地方,所以看起来很容易上手.下面是学习笔记! package testbotoo; public c ...

  4. linux===linux后台运行和关闭、查看后台任务(转)

    fg.bg.jobs.&.ctrl + z都是跟系统任务有关的,虽然现在基本上不怎么需要用到这些命令,但学会了也是很实用的 一.& 最经常被用到这个用在一个命令的最后,可以把这个命令放 ...

  5. HDU 4305 Lightning Matrix Tree定理

    题目链接:https://vjudge.net/problem/HDU-4305 解法:首先是根据两点的距离不大于R,而且中间没有点建立一个图.之后就是求生成树计数了. Matrix-Tree定理(K ...

  6. 关于:TypeConverter 无法从 System.String 转换

    TypeConverter 无法从 System.String 转换 处理方法: 1: [DX Support Team: The issue was resolved by its Owner] i ...

  7. IE6下面的浮动问题

    第一个问题: 在IE6下面overflow:hidden;失效      原因:在IE6/7中子级设置position:relative;属性值后,导致父级的overflow:hidden;失效.   ...

  8. 取消div,a等标签点击效果

    当标签被设置onclick事件之后,在有些手机浏览器中,点击这些标签,会有点击变色效果.想要取消点击变色效果. 添加:div{-webkit-tap-highlight-color:rgba(0,0, ...

  9. linux命令(22):mkdir命令

    实例1:创建一个空目录 mkdir  test 实例2:递归创建多个目录 mkdir  -p /home/test 实例3:创建权限为777的目录 mkdir -m 777 test 实例4:创建新目 ...

  10. scala中常用特殊符号

    参考资料: scala中常用但其他语言不常见的符号含义 Scala学习六:Scala中的特殊字符 =>(匿名函数) 参考文档:scala => 用法 匿名函数 => 匿名函数,在Sp ...