题目:

Atlantis
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 23758   Accepted: 8834

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 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

 
  思路:
    矩形面积并,复习下。
 #include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=3e2+;
const int mod=1e9+; struct node
{
int f;
double l,r,y;
bool operator < (const node &ta)const
{
return y<ta.y;
}
}seg[K*];
int cover[K*];
double sum[K*],hs[K*];
void push_up(int o,int l,int r)
{
if(cover[o]) sum[o]=hs[r+]-hs[l];
else if(l==r) sum[o]=;
else sum[o]=sum[o<<]+sum[o<<|];
}
void update(int o,int l,int r,int nl,int nr,int f)
{
if(l==nl&&r==nr)
cover[o]+=f,push_up(o,l,r);
else
{
int mid=l+r>>;
if(nr<=mid) update(o<<,l,mid,nl,nr,f);
else if(nl>mid) update(o<<|,mid+,r,nl,nr,f);
else update(o<<,l,mid,nl,mid,f),update(o<<|,mid+,r,mid+,nr,f);
push_up(o,l,r);
}
}
int main(void)
{
int n,cs=;
while(scanf("%d",&n)&&n)
{
int cnt=;
double ans=;
memset(cover,,sizeof cover);
memset(sum,,sizeof sum);
for(int i=;i<=n;i++)
{
double lx,ly,rx,ry;
scanf("%lf%lf%lf%lf",&lx,&ly,&rx,&ry);
seg[cnt+].l=seg[cnt+].l=lx;
seg[cnt+].r=seg[cnt+].r=rx;
seg[cnt+].y=ry,seg[cnt+].y=ly;
seg[cnt+].f=,seg[cnt+].f=-;
hs[cnt+]=lx,hs[cnt+]=rx;
cnt+=;
}
sort(seg+,seg++n*);
sort(hs+,hs++*n);
int sz=unique(hs+,hs++n*)-hs;
for(int i=;i<*n;i++)
{
int l=lower_bound(hs+,hs+sz,seg[i].l)-hs;
int r=lower_bound(hs+,hs+sz,seg[i].r)-hs;
update(,,sz,l,r-,seg[i].f);
ans+=sum[]*(seg[i+].y-seg[i].y);
}
printf("Test case #%d\nTotal explored area: %.2f\n\n",cs++,ans);
}
return ;
}

poj1151 Atlantis && cdoj 1600艾尔大停电 矩形面积并的更多相关文章

  1. [POJ1151]Atlantis

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

  2. Three.js 火焰效果实现艾尔登法环动态logo 🔥

    声明:本文涉及图文和模型素材仅用于个人学习.研究和欣赏,请勿二次修改.非法传播.转载.出版.商用.及进行其他获利行为. 背景 <艾尔登法环>是最近比较火的一款游戏,观察可以发现它的 Log ...

  3. (HDU 1542) Atlantis 矩形面积并——扫描线

    n个矩形,可以重叠,求面积并. n<=100: 暴力模拟扫描线.模拟赛大水题.(n^2) 甚至网上一种“分块”:分成n^2块,每一块看是否属于一个矩形. 甚至这个题就可以这么做. n<=1 ...

  4. HDU 1542 Atlantis(矩形面积并)

    HDU 1542 Atlantis 题目链接 题意:给定一些矩形,求面积并 思路:利用扫描线,因为这题矩形个数不多,直接暴力扫就能够了.假设数据大.就要用线段树 代码: #include <cs ...

  5. POJ 1151 Atlantis 线段树求矩形面积并 方法详解

    第一次做线段树扫描法的题,网搜各种讲解,发现大多数都讲得太过简洁,不是太容易理解.所以自己打算写一个详细的.看完必会o(∩_∩)o 顾名思义,扫描法就是用一根想象中的线扫过所有矩形,在写代码的过程中, ...

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

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

  7. 10.我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。 请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?

    我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形. 请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 是不是发现看不懂,哈哈:编程题就是这样,一定要归纳,手写过程: n ...

  8. poj-1151矩形面积并-线段树

    title: poj-1151矩形面积并-线段树 date: 2018-10-30 22:35:11 tags: acm 刷题 categoties: ACM-线段树 概述 线段树问题里的另一个问题, ...

  9. hdu 1542&&poj 1151 Atlantis[线段树+扫描线求矩形面积的并]

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

随机推荐

  1. 【渗透测试学习平台】 web for pentester -4.目录遍历

    Example 1 http://192.168.106.154/dirtrav/example1.php?file=../../../../../../../etc/passwd Example 2 ...

  2. C++说明符和限定符

    有些被称为存储说明符(storage class specifier)或cv-限定符(cv-qualifier)的C++关键字提供了一些有关存储的信息.下面是存储所说明符:* auto (在C++11 ...

  3. 宏(define)与常量(const)

    http://mp.weixin.qq.com/s?__biz=MzAxMzE2Mjc2Ng==&mid=402470669&idx=1&sn=e34db91190d8d46f ...

  4. iOS - UITableView滚动到指定的cell并且选中

    UITableView //项目中遇到的 - (void)selectRowAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)a ...

  5. linux配置免密登录

    例如: $ ssh -i ~/ec2.pem ubuntu@12.34.56.78 首先确定你可以以密码的形式连接远程服务器,也可以创建一个非超级管理员用户,并增加 sudo 权限. $ sudo s ...

  6. WEB安全第二篇--用文件搞定服务器:任意文件上传、文件包含与任意目录文件遍历

    零.前言 最近做专心web安全有一段时间了,但是目测后面的活会有些复杂,涉及到更多的中间件.底层安全.漏洞研究与安全建设等越来越复杂的东东,所以在这里想写一个系列关于web安全基础以及一些讨巧的pay ...

  7. 网络下载功能实现(downloader ) ---- HTML5+

    模块:downloader Downloader模块管理网络文件下载任务,用于从服务器下载各种文件,并支持跨域访问操作.通过plus.downloader获取下载管理对象.Downloader下载使用 ...

  8. postgresql----Btree索引

    当表数据量越来越大时查询速度会下降,像课本目录一样,在表的条件字段上创建索引,查询时能够快速定位感兴趣的数据所在的位置.索引的好处主要有加速带条件的查询,删除,更新,加速JOIN操作,加速外键约束更新 ...

  9. Oracle之rman命令的使用(51CTO风哥rman课程)

    看rman的连接串的帮助 连接数据库 rman target/ rman的版本要和目标数据库一致(一般大版本可以往下兼容小版本) 运行操作系统命令 run {host "pwd"; ...

  10. 牛客网多校赛第七场J--Sudoku Subrectangle

    链接:https://www.nowcoder.com/acm/contest/145/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6553 ...