小数据求面积并

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

Source

Mid-Central Europe 2000

这个直接用了二分查询,但是复杂度还是蛮高的

#include<bits/stdc++.h>
using namespace std;
const int N=;
const double eps=1e-;
int n,vis[N],t;
double has[N];
struct line
{
double l,r,y;
int f;
line(){}
line(double l,double r,double y,int f):l(l),r(r),y(y),f(f){}
}L[N];
bool cmp(line a,line b)
{
return a.y<b.y;
}
int get(double x)
{
return lower_bound(has,has+t,x)-has;
}
int main()
{
int ca=,i,j;
double x1,y1,x2,y2;
while(scanf("%d",&n),n)
{
t=;
memset(vis,,sizeof vis);
for(i=; i<n; i++)
{
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
L[t]=line(x1,x2,y1,),has[t++]=x1;
L[t]=line(x1,x2,y2,-),has[t++]=x2;
}
n*=;
sort(L,L+n,cmp);
sort(has,has+t);
t=;
for(i=;i<n;i++)
if(fabs(has[i]-has[i-])>eps)has[t++]=has[i];
double res=;
for(i=; i<n; i++)
{
int l=get(L[i].l),r=get(L[i].r);
double len=;
for(j=;j<t-;j++)
if(vis[j]>)len+=has[j+]-has[j];
if(i)res+=len*(L[i].y-L[i-].y);
for(j=l;j<r;j++)vis[j]+=L[i].f;
}
printf("Test case #%d\nTotal explored area: %.2f\n\n",++ca,res);
}
return ;
}

TOJ2712: Atlantis的更多相关文章

  1. [POJ1151]Atlantis

    [POJ1151]Atlantis 试题描述 There are several ancient Greek texts that contain descriptions of the fabled ...

  2. 线段树---Atlantis

    题目网址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110064#problem/A Description There are se ...

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

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

  4. 【POJ】1151 Atlantis(线段树)

    http://poj.org/problem?id=1151 经典矩形面积并吧.....很简单我就不说了... 有个很神的地方,我脑残没想到: 将线段变成点啊QAQ这样方便计算了啊 还有个很坑的地方, ...

  5. HDU 1542 Atlantis(线段树扫描线+离散化求面积的并)

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

  6. POJ 1542 Atlantis(线段树 面积 并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 参考网址:http://blog.csdn.net/sunmenggmail/article/d ...

  7. [POJ 1151] Atlantis

    一样的题:HDU 1542 Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18148   Accepted ...

  8. 【HDU 1542】Atlantis 矩形面积并(线段树,扫描法)

    [题目] Atlantis Problem Description There are several ancient Greek texts that contain descriptions of ...

  9. 【POJ1151】【扫描线+线段树】Atlantis

    Description There are several ancient Greek texts that contain descriptions of the fabled island Atl ...

随机推荐

  1. 我们为什么要看《超实用的HTML代码段》

    不知道自己HTML水平如何,不知道HTML5如何进化?看这张图 如果一半以上的你都不会,必须看这本书,阿里一线工程师用代码和功能页面来告诉你每一个技术点. 都会一点,但不知道如何检验自己,看看本书提供 ...

  2. 如何提高Mysql的查询效率???

    1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...

  3. SharePoint 2013 安装配置(2)

    上一篇中,我们已经安装了Windows Server 2012 R2.现在第二部分,如何在Windows Server 2012 R2中安装Active Directory域控制器.请按照以下步骤. ...

  4. 地址栏传值 JS取值方法

    function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&] ...

  5. UVA12906 Maximum Score (组合)

    对于每个元素,最理想的情况就是都在它的左边或者右边,那么sort一下就可以得到一个特解了,然后大的中间不能有小的元素,因为如果有的话,那么无论选小的还是选大的都不是最优.对小的元素来说,比它大的元素在 ...

  6. spring maven 包

    <spring-framework.version>.RELEASE</spring-framework.version> <dependency> <gro ...

  7. 原型模式 -- JavaScript语言的灵魂

    原型模式就是将原型对象指向创建对象的类,使这些类共享原型对象的方法与属性.JS是基于原型链实现对象之间的继承,是对属性或者方法的共享,而不是对属性和方法的复制. // 图片轮播类 var LoopIm ...

  8. JsonPath 语法 与 XPath 对比

    JsonPath 语法 与 XPath 对比   XPath JSONPath Description / $ the root object/element . @ the current obje ...

  9. 访问URI地址

    //发送消息到服务器 public string HttpConnectToServer(string ServerPage) { byte[] dataArray = Encoding.Defaul ...

  10. 瀑布流封装(仿写UITableView)

    本篇文章将会仿照苹果系统提供的UITableView类,封装一个瀑布流效果的控件!!! 该控件和系统的UITableView是相同级别的 (继承自系统的UIScrollView) GitHub中Dem ...