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. ContentProvider的使用

    这方面的资料应该网上已经很多了,我在这里只是做简单的总结就行了. 如题:ContentProvider是android的内容提供器,可以为应用程序提供各种的数据,例如数据表,txt文件,xml文件等等 ...

  2. 安装github for windows问题解决

    到官网下载windows环境下的github,在安装时出现下面问题 An error occurred trying to download 'http://github-windows.s3.ama ...

  3. wind river hypervisor 2.0.2.1

    2692407267@qq.com,请注意很多其他内容http://user.qzone.qq.com/2692407267 wind river hypervisor 2.0.2.1 版权声明:本文 ...

  4. vpdn详细说明

     VPDN英文为Virtual Private Dial-up Networks,又称为虚拟专用拨号网,是VPN业务的一种,是基于拨号用户的虚拟专用拨号网业务. 中文名 虚拟专用拨号网业务 外文名 ...

  5. Apple Watch 1.0 开发介绍 1.1 简介 开发苹果手表

    使用Apple Watch,用户可以使用一种不显眼的方式查看信息.不用把iPhone从口袋里拿出来,就可以通过看一下手表快速获得重要信息. 作为Apple Watch的第三方app开发者,应该通过使用 ...

  6. c# winform 引用sqlite.dll 运行报错解决方法

    错误信息 :  未能加载文件或程序集“System.Data.SQLite, Version=1.0.81.0, Culture=neutral, PublicKeyToken=db937bc2d44 ...

  7. RH133读书 笔记(3) - Lab 3 Configuring the kernel

    Lab 3 Configuring the kernel Goal: Develop skills tuning the /proc filesystem. Gain some experience ...

  8. struts2于validate要使用

    package com.test.action; import com.opensymphony.xwork2.ActionSupport; import com.test.model.User; p ...

  9. ASP.NET 异步编程

    ASP.NET 异步编程 相关博文: 异步编程 In .NET(回味无穷!!!) ASP.NET sync over async(异步中同步,什么鬼?) 本来这篇博文想探讨下异步中的异常操作,但自己在 ...

  10. SQL 2008 SP2 找不到SQL Server Engine

    原文:SQL 2008 SP2 找不到SQL Server Engine 最近我有个客户碰到一个很奇怪的问题.他安装SQL server 2008 SP2的时候, SP2的安装程序无法找到SQL se ...