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. 学习jQuery的事件dblclick

    Insus.NET一直以来都是asp.net的开发的,少使用javascript.现在学习asp.net mvc了,jQuery是一个必须掌握的客户端语言. 不用急,慢慢来.一步一步.这篇练习jQue ...

  2. asp.net Get和Post传参和接收参数

    asp.netGet和Post传参和接收参数 Get请求: 对于传参:test.aspx?name=%e5%bc%a0%e4%b8%89 接收参数的方法: Request.QueryString[&q ...

  3. Cocos2dx 3.x包含ext库报错解决

    之前使用cocos2dx 3.6版本中用到了ext库中的一些东西,使用visual studio 2013,编译的时候报错: 无法打开包括文件:“extensions/ExtensionMacros. ...

  4. 进入IT企业必读的200个.NET面试题

    点击打开链接 点击打开链接 版权声明:本文为博主原创文章,未经博主允许不得转载.

  5. 重新想象 Windows 8.1 Store Apps (84) - 图像处理的新特性, Share Contract 的新特性

    [源码下载] 重新想象 Windows 8.1 Store Apps (84) - 图像处理的新特性, Share Contract 的新特性 作者:webabcd 介绍重新想象 Windows 8. ...

  6. EasyUI个人项目晒图(续)

    晒自己做的一个管理系统(清新风格)EasyUI 这是自己上一次的文章了,只是给大家看一下自己的美观度是不是还是停留在新手的阶段!反正我自己认为我已经不是一个新手了吧!虽然技术永远学不完,我可以说,我和 ...

  7. C程序(3)

  8. MyKTV项目总结

    今天和大伙分享一下我的KTV系统,我想大家都有自己独特的魅力,都有自己的风采,都有自己骄傲的一部分. 在这里我就抛砖引玉,聊聊我的KTV项目,希望大家能给出自己的建议.. 首先,我们先了解一下:当我们 ...

  9. 简单封装cookie操作

    1 //设置cookie 2 function setCookie(name, value, day) { 3 var oDate = new Date(); 4 oDate.setDate(oDat ...

  10. CSS3 实现简单轮播图

    用css3动画实现图片切换效果,原理还是改变left值.只有最简单的自动播放功能,切换后短时间静止,通过最后的位置克隆第一张图片,实现无缝切换. html结构 <div id="con ...