Atlantis

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 7815    Accepted Submission(s): 3420

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
求面积并:
推荐博客:http://www.cnblogs.com/ka200812/archive/2011/11/13/2247064.html
我的代码:
#include <cstdio>
#include <algorithm> using namespace std ; double y[300] ; struct Line{
double x , y_up , y_down ;
int mark ;
}line[300] ; //開始开到110,WA另外三次。! 后来看discuss改后就A了! struct Node{
double x ,y_up,y_down ;
int cover ;
bool isLeaf ;
}st[400100]; bool cmp(const Line &a , const Line &b)
{
return a.x<b.x ;
} void build(int l ,int r , int pos)
{
st[pos].cover = 0 ;
st[pos].y_down = y[l] ;
st[pos].y_up = y[r] ;
st[pos].x = -1 ;
st[pos].isLeaf = false ;
if(l+1 == r)
{
st[pos].isLeaf = true ;
return ;
}
int mid = (l+r)>>1 ;
build(l,mid,pos<<1);
build(mid,r,pos<<1|1) ;
} double insert(double x , double y_up , double y_down , int mark , int pos)
{
if(st[pos].y_down>=y_up || st[pos].y_up<=y_down)
{
return 0 ;
}
if(st[pos].isLeaf)
{
if(st[pos].cover>0)
{
double temp = st[pos].x ;
double area = (x-temp)*(st[pos].y_up-st[pos].y_down) ;
st[pos].x = x ;
st[pos].cover += mark ;
return area ;
}
else
{
st[pos].x = x ;
st[pos].cover += mark ;
return 0 ;
}
}
return insert(x,y_up,y_down,mark,pos<<1)+insert(x,y_up,y_down,mark,pos<<1|1) ;
} int main()
{
int n , c = 1;
while(~scanf("%d",&n) && n)
{
int index = 0 ;
for(int i = 0 ; i < n ; ++i)
{
double x1,y1,x2,y2 ;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2) ;
line[index].x = x1 ;
line[index].y_down = y1 ;
line[index].y_up = y2 ;
y[index] = y1 ;
line[index++].mark = 1 ; line[index].x = x2 ;
line[index].y_down = y1 ;
line[index].y_up = y2 ;
y[index] = y2 ;
line[index++].mark = -1 ;
}
sort(y,y+index) ;
sort(line,line+index,cmp) ;
build(0,index-1,1) ;
double area = 0.0 ;
for(int i = 0 ; i < index ; ++i)
{
area += insert(line[i].x,line[i].y_up,line[i].y_down,line[i].mark,1) ;
}
printf("Test case #%d\n",c++) ;
printf("Total explored area: %.2lf\n\n",area) ;
}
return 0 ;
}

而共勉之王

hdu 1542 Atlantis 段树区,并寻求,,,尼玛真坑人数据,不要打开一小阵!的更多相关文章

  1. hdu 1542 Atlantis(段树&amp;扫描线&amp;面积和)

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

  2. HDU 1542 - Atlantis - [线段树+扫描线]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  3. HDU 1542.Atlantis-线段树求矩形面积并(离散化、扫描线/线段树)-贴模板

    好久没写过博客了,这学期不是很有热情去写博客,写过的题也懒得写题解.现在来水一水博客,写一下若干年前的题目的题解. Atlantis Time Limit: 2000/1000 MS (Java/Ot ...

  4. hdu 1542 Atlantis(线段树,扫描线)

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

  5. HDU 1542 Atlantis(线段树面积并)

     描述 There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. S ...

  6. HDU 1542 Atlantis (线段树 + 扫描线 + 离散化)

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

  7. POJ 1151 / HDU 1542 Atlantis 线段树求矩形面积并

    题意:给出矩形两对角点坐标,求矩形面积并. 解法:线段树+离散化. 每加入一个矩形,将两个y值加入yy数组以待离散化,将左边界cover值置为1,右边界置为2,离散后建立的线段树其实是以y值建的树,线 ...

  8. hdu 1542 Atlantis (线段树扫描线)

    大意: 求矩形面积并. 枚举$x$坐标, 线段树维护$[y_1,y_2]$内的边是否被覆盖, 线段树维护边时需要将每条边挂在左端点上. #include <iostream> #inclu ...

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

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

随机推荐

  1. [windows phone] 教你如何使地图动画缩放

    原文:[windows phone] 教你如何使地图动画缩放 说明 本篇将介绍如何将地图以动画显示呈现,在以下的范例介绍中可以看到有动画跟没动画的差别,如果你的地图还是很单调的话,不仿加上这个设计,让 ...

  2. SpringMVC 上下文webApplicationContext

    使用listener听众载入配置,一般Struts+Spring+Hibernate是使用listener监听器的.例如以下 <listener> <listener-class&g ...

  3. Oracle GoldenGate (以下简称ogg)在异种移植os同一种db之间的数据同步。

    Oracle GoldenGate (以下简称ogg)在异种移植os同一种db之间的数据同步. ogg要实现的功能: 同步可以细化到单个表,满足特定的where条件rows同步,称号column同步. ...

  4. mysql监视器MONyog的使用

    MONyog是个商业收费软件,可是能够找一下破解版.我用的是4.72破解版 1.       图1.1 在server设置中,如图1.1. 在Sniffer Settings里Enable sniff ...

  5. JAVA字符串格式化-String.format()使用

    传统型格类型 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象. 熟悉C语言的同学应该记得C语言的sprintf()方法.两者有类似之处.format()方法有两种重载 ...

  6. hdu 4296 Buildings(贪婪)

    主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=4296 Buildings Time Limit: 5000/2000 MS (Java/Others ...

  7. Chapter 1 Securing Your Server and Network(2):管理服务的SIDs

    原文出处:http://blog.csdn.net/dba_huangzj/article/details/37927319 ,专题文件夹:http://blog.csdn.net/dba_huang ...

  8. 搭建SSH

    搭建SSH详细步骤及相关说明   因为手里已有相关jar,为方便我搭建的是:Struts2.0+Hibernate3.3+Spring3.0,数据库:MySQL 如果想搭建最新的,在官网上下载最新ja ...

  9. MVC 应用免受 CSRF攻击

    保护ASP.NET 应用免受 CSRF 攻击   CSRF是什么? CSRF(Cross-site request forgery),中文名称:跨站请求伪造,也被称为:one click attack ...

  10. 【Nginx】磁盘文件写入飞地发

    文章继续.什么时候Nginx当用户请求一个文件,这将无法读取该文件的内容加载到内存,然后从内存发送,但电话sendfile况下,从内核直接发送出去.这样做显然效率要更高.Nginx也为我们封装好了一系 ...