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. winform去掉右上角关闭按钮

    一种方法是可以在窗体的属性面板将窗体的 ControlBox属性设置为false,或者在窗体的构造函数中这样写: public Form1() { InitializeComponent(); thi ...

  2. 用C#编程的建议

    1.如果可能尽量使用接口来编程       .NET框架包括类和接口,在编写程序的时候,你可能知道正在用.NET的哪个类.然而,在这种情况下如果你用.NET支持的接口而不是它的类来编程时,代码会变得更 ...

  3. Python入门笔记(18):Python函数(1):基础部分

    一.什么是函数.方法.过程 推荐阅读:http://www.cnblogs.com/snandy/archive/2011/08/29/2153871.html 一般程序设计语言包含两种基本的抽象:过 ...

  4. iOS开发系列通讯录、蓝牙、内购、GameCenter、iCloud、Passbook系统服务开

    --系统应用与系统服务 iOS开发过程中有时候难免会使用iOS内置的一些应用软件和服务,例如QQ通讯录.微信电话本会使用iOS的通讯录,一些第三方软件会在应用内发送短信等.今天将和大家一起学习如何使用 ...

  5. python中的__init__ 、__new__、__call__小结

    这篇文章主要介绍了python中的__init__ .__new__.__call__小结,需要的朋友可以参考下 1.__new__(cls, *args, **kwargs)  创建对象时调用,返回 ...

  6. shape和selector的结合

    去掉gridview本身的点击效果:android:listSelector="@color/de_transparent": 添加两个selector,灰色的press和norm ...

  7. Linux FTP配置文件说明

    一.vsftpd说明: LINUX下实现FTP服务的软件很多,最常见的有vsftpd,Wu-ftpd和Proftp等.Red Hat Enterprise Linux中默认安装的是vsftpd. 访问 ...

  8. 研究jdk关于TreeMap 红黑树算法实现

    因为TreeMap的实现方式是用红黑树这种数据结构进行存储的,所以呢我主要通过分析红黑树的实现在看待TreeMap,侧重点也在于如何实现红黑树,因为网上已经有非常都的关于红黑树的实现.我也看了些,但是 ...

  9. 实验12:Problem D: 判断两个圆之间的关系

    Home Web Board ProblemSet Standing Status Statistics   Problem D: 判断两个圆之间的关系 Problem D: 判断两个圆之间的关系 T ...

  10. 关于ApplicationPoolIdentity

    一直以来IIS中的网站默认都是以network service在运行,但是从IIS7开始,默认会以ApplicationPoolIdentity运行. 这个账户比较特殊,是一种虚拟帐户,你无法在计算机 ...