Atlantis

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

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   ::这道题我是参考hh博客上的代码。用线段树来保存当前被覆盖的线段长度总和。 建议:如果刚学线段树+扫描线,最好把那sample input 作为测试数据输出中间变量的值, 这样可以有更深的理解   代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const int N=500;
double sum[N<<2];
int col[N<<2];
double x[N]; struct node
{
double l,r,h;
int s;
bool operator < (const node & t) const {
return h<t.h;
}
}e[N]; void add(node &e,double l,double r,double h,int s)
{
e.l=l; e.r=r; e.h=h; e.s=s;
} int Bina(double x[],int n,double a)
{
int l=0,r=n-1;
while(l<=r)
{
int m=(l+r)>>1;
if(x[m]==a) return m;
if(x[m]<a) l=m+1;
else r=m-1;
}
return -1;
} void PushUp(int rt,int l,int r)
{
if(col[rt]) sum[rt]=x[r+1]-x[l];
else sum[rt]=sum[rt<<1]+sum[rt<<1|1];
} void update(int L,int R,int c,int l,int r,int rt)
{
if(L<=l&&R>=r)
{
col[rt]+=c;
PushUp(rt,l,r);
return ;
}
int m=(l+r)>>1;
if(L<=m) update(L,R,c,lson);
if(R>m) update(L,R,c,rson);
PushUp(rt,l,r);
} int main()
{
// freopen("in.txt","r",stdin);
int n,cas=1;
while(scanf("%d",&n)>0&&n)
{
int k=0,i;
for(i=0; i<n; i++)
{
double a,b,c,d;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
x[k]=a;
add(e[k++],a,c,b,1);
x[k]=c;
add(e[k++],a,c,d,-1);
}
sort(e,e+k);
///////离散化////////////////////////////////////
sort(x,x+k);
int m=1;
for(i=1; i<k; i++)
{
if(x[i]!=x[i-1])
x[m++]=x[i];
}
////////////////////////////////////////////////
// for(i=0; i<m ;i++) printf("x[%d]=%lf\n",i,x[i]);
// for(i=0; i<k; i++) printf("%d-> l=%lf, r=%lf, h=%lf ..s=%d\n",i,e[i].l,e[i].r,e[i].h,e[i].s); memset(sum,0,sizeof(sum));
memset(col,0,sizeof(col));
double ans=0;
for(i=0; i<k-1; i++)
{
int L=Bina(x,m,e[i].l);
int R=Bina(x,m,e[i].r)-1;
if(L<=R) update(L,R,e[i].s,0,k-1,1);
// printf("L=%d, x[L]=%lf ; R=%d, x[R]=%lf\n",L,x[L],R,x[R]);
// printf("覆盖区间长度=%lf\n",sum[1]);
ans+=(e[i+1].h-e[i].h)*sum[1];//e[i+1].h-e[i].h是固定的长度H,sum[1]是在覆盖在H区域内的线段有多长
}
printf("Test case #%d\nTotal explored area: %.2lf\n\n",cas++,ans);
}
return 0;
}

 

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

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

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

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

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

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

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

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

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

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

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

  6. Atlantis HDU - 1542 (线段树扫描线)

    There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...

  7. hdu 1542(线段树+扫描线 求矩形相交面积)

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

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

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

  9. hdu1542 Atlantis 线段树--扫描线求面积并

    There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...

随机推荐

  1. 【iOS】XcodeColors插件与CocoaLumberjack工具

    工欲善其事必先利其器,好的开发者一定是懂得利用工具来提高自己的效率的,Xcode有很多第三方插件可以使用,最近发现一个可以给控制台着色的工具XcodeColors,结合CocoaLumberjack一 ...

  2. vim 正则替换

    http://www.cppblog.com/kefeng/archive/2010/10/20/130574.html Vim中的正则表达式功能很强大,如果能自由运用,则可以完成很多难以想象的操作. ...

  3. [PE结构分析] 6.IMAGE_SECTION_HEADER

    IMAGE_SECTION_HEADER 的源代码如下: typedef struct _IMAGE_SECTION_HEADER { BYTE Name[IMAGE_SIZEOF_SHORT_NAM ...

  4. bootstrap 学习片段

    1. 只要单击按钮添加了data-toggle="dropdown"属性, 在单击按钮的时候,默认隐藏的下拉列表就会显示出来 <div class="row&quo ...

  5. 你还记的那一年你我学习的-->>用表组织数据*(数据表)

    不知不觉,踏上IT之路,光阴似箭,日月如梭.虽好像回到从前,回到那个无忧无虑的童年,回到那个花样少年的青春;回到那个年少幼稚的小学;回到那个整天幻想的初中;回到那个顽强不屈,誓死不弃的高中;回到那个整 ...

  6. 一个H5的3D滑动组件实现(兼容2D模式)

    起由 原始需求来源于一个项目的某个功能,要求实现3D图片轮播效果,而已有的组件大多是普通的2D图片轮播,于是重新造了一个轮子,实现了一个既支持2D,又支持3D的滑动.轮播组件. 实现思路 刚一开始肯定 ...

  7. Vue混合

    gitHub地址: https://github.com/lily1010/vue_learn/tree/master/lesson13 一 定位 混合以一种灵活的方式为组件提供分布复用功能.混合对象 ...

  8. 通用javascript方法

    //将序列化成json格式后日期(毫秒数)转成日期格式 YYYY-MM-DD HH:MI:SS function ChangeDateFormat(cellval, type) { var date ...

  9. VS 2013打开.edmx文件时报类型转换异常

      供应商提交了项目代码,但在我的电脑上打开项目编译时一直报Entityframework 的 .edmx文件转换异常,而无法通过编译.   分析后认为可能是entityframework的类库不够新 ...

  10. Python开发包推荐系列之xml、html解析器PyQuery

    使用python,喜欢她的简洁是一方面,另外就是它有着丰富的开发包 好用又方便 接下来会给大家推荐一系列很赞的开发包. 在解析html.xml过程中,我们有不少的包可以用.比如bs.lxml.xmlt ...