小数据求面积并

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. Selenium3+webdriver学习笔记2(常用元素定位方式,定位单个元素共8种,总共有23种)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriver import time,os # about:ad ...

  2. Redis相关注意事项

    本文介绍了五个使用Redis使用时的注意事项.如果你在使用或者考虑使用Redis,你可以学习一下下面的一些建议,避免遇到以下提到的问题. 一.配置相关注意事项 1.涉及到内存的单位注意添加 b 1k ...

  3. COGS 2104. [NOIP2015]神奇的幻方

    ★   输入文件:2015magic.in   输出文件:2015magic.out   简单对比时间限制:1 s   内存限制:256 MB 模拟 一开始数组开小了.. 屠龙宝刀点击就送 #incl ...

  4. 如何处理错误消息Please install the Linux kernel header files

    Please install the Linux kernel "header" files matching the current kernel 当我启动minilkube时遇 ...

  5. sum特殊用法

    在python中,list可以存储False和True a = [False] python的sum除了可以加数字,还可以计算列表中False,True的个数,默认是计算False个数 >> ...

  6. 【转】Popclip的JSON格式化扩展

    http://liuyunclouder.github.io/2016/09/29/JSONizer:Popclip的JSON格式化扩展 作为一个MAC党,不好好利用MAC的神兵利器,简直就是罪过.A ...

  7. Linux curl命令中,HTTP 302处理

    在Linux中使用curl命令时,偶尔会遇到一些URL跳转到新的URL,即HTTP中的3XX(redirection,重定向 ). $curl -s -I $URL > log 这时在返回的报文 ...

  8. 自然数的拆分(DFS)

    题目描述: 任何一个大于1的自然数n,总可以拆分成若干个小于n的自然数之和. 输入格式: 待拆分的自然数n. 输出格式: 若干数的加法式子. 样例输入: 7 样例输出: 1+1+1+1+1+1+1 1 ...

  9. (73)zabbix用户认证方式 内建、HTTP Basic、LDAP

    公司大大小小众多系统,不同系统不同的账号密码,管理上相当复杂,后来慢慢出现了SSO等账号统一验证,其他zabbix也提供了类似的方法,或许有些公司便可以使用公司提供的账号来登录zabbix了. zab ...

  10. Jquery之 Ajax /json

    前言: Ajax = Asynchronous JavaScript and XML(异步的JavaScript和XML) Ajax不是新的编程语言,而是一种使用现有标准的新方法. Ajax最大的优点 ...