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. SQLServer 网络协议(一)

    SQLserver现在主要的3种协议:Shared Memory.TCP/IP 和 Named Pipe SharedMemory: Shared Memory最快最简单的协议,使用SharedMem ...

  2. android集成apk对一些问题经常遇到系统

    1.集成APK必须确认是否release版本号,否则会导致CTS测试失败. 途径:反编译apk,视图manifest.xml文件,看<application>在那里debug属性:andr ...

  3. JSP简单的练习-用户登记表

    <%@ page language="java" import="java.util.*" pageEncoding="gb2312" ...

  4. 输出A打头的字符串

    题目描述 输出n个字符串,把其中以字母A打头的字符串输出. 输入 第一行 n 第二行到第n+1行,每行一个字符串 输出 A打头的字符串 样例输入 3 Ada Bob Alice 样例输出 Ada Al ...

  5. Java知多少(87)选择框和单选按钮(转)

    选择框.单选框和单选按钮都是选择组件,选择组件有两种状态,一种是选中(on),另一种是未选中(off),它们提供一种简单的 “on/off”选择功能,让用户在一组选择项目中作选择. 选择框 选择框(J ...

  6. 深入理解Javascript闭包概念

    一.变量的作用域 要理解闭包,首先必须理解Javascript特殊的变量作用域. 变量的作用域无非就是两种:全局变量和局部变量. Javascript语言的特殊之处,就在于函数内部能够直接读取全局变量 ...

  7. 开源Math.NET基础数学类库使用(08)C#进行数值积分

    原文:[原创]开源Math.NET基础数学类库使用(08)C#进行数值积分               本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p/4 ...

  8. python django模型内部类meta详细解释

    Django 模型类的Meta是一个内部类,它用于定义一些Django模型类的行为特性.下面对此作一总结: abstract      这个属性是定义当前的模型类是不是一个抽象类.所谓抽象类是不会相应 ...

  9. 无尽的循环ViewPager

    现在的情况 不改变的源代码,什么时候ViewPager滑动到最后item的时候,他就无法再往右滑动:当ViewPager滑动到第一个item的时候,他也无法再往前滑动. (以上全是废话) 设想 我们能 ...

  10. ios崩溃日志1

    Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not loa ...