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.

题意:给出若干个矩形,求他们的总面积,即矩形的面积并

求面积并是线段树-扫描线的裸题

 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxm=; int cov[maxm<<];
double y[maxm],st[maxm]; struct seg{
double x,y1,y2;
int c;
bool operator < (const seg a)const{
return x<a.x;
}
}s[maxm]; void pushup(int o,int l,int r){
if(cov[o]>)st[o]=y[r]-y[l];
else if(cov[o]==){
if(l+==r)st[o]=;
else st[o]=st[o<<]+st[o<<|];
}
} void update(int o,int l,int r,seg a){
if(a.y1<=y[l]&&a.y2>=y[r]){
cov[o]+=a.c;
pushup(o,l,r);
return;
}
if(l+==r)return;
int m=l+((r-l)>>);
if(a.y1<y[m])update(o<<,l,m,a);
if(a.y2>y[m])update(o<<|,m,r,a);
pushup(o,l,r);
} int main(){
int n;
int c=;
while(scanf("%d",&n)!=EOF&&n){
memset(st,,sizeof(st));
memset(cov,,sizeof(cov));
for(int i=;i<=n;++i){
double x1,y1,x2,y2;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
s[*i-].x=x1;s[*i-].y1=y1;s[*i-].y2=y2;s[*i-].c=;
y[*i-]=y1;
s[*i].x=x2;s[*i].y1=y1;s[*i].y2=y2;s[*i].c=-;
y[*i]=y2;
}
sort(s+,s+*n+);
sort(y+,y+*n+);
double ans=;
int cnt=;
for(int i=;i<=*n;++i){
if(y[i]!=y[i-])y[++cnt]=y[i];
}
for(int i=;i<*n;++i){
update(,,cnt,s[i]);
ans+=st[]*(s[i+].x-s[i].x);
}
printf("Test case #%d\n",++c);
printf("Total explored area: %.2lf\n\n",ans);
}
return ;
}

hdu1542 Atlantis 线段树--扫描线求面积并的更多相关文章

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

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

  2. hdu1542 线段树扫描线求矩形面积的并

    题意:       给你n个正方形,求出他们的所占面积有多大,重叠的部分只能算一次. 思路:       自己的第一道线段树扫描线题目,至于扫描线,最近会写一个总结,现在就不直接在这里写了,说下我的方 ...

  3. HDU 1542 - Atlantis - [线段树+扫描线]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  4. HDU 1264 Counting Squares (线段树-扫描线-矩形面积并)

    版权声明:欢迎关注我的博客.本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/25471349 P ...

  5. HDU 1828“Picture”(线段树+扫描线求矩形周长并)

    传送门 •参考资料 [1]:算法总结:[线段树+扫描线]&矩形覆盖求面积/周长问题(HDU 1542/HDU 1828) •题意 给你 n 个矩形,求矩形并的周长: •题解1(两次扫描线) 周 ...

  6. HDU 1542"Atlantis"(线段树+扫描线求矩形面积并)

    传送门 •题意 给你 n 矩形,每个矩形给出你 $(x_1,y_1),(x_2,y_2)$ 分别表示这个矩形的左下角和右上角坐标: 让你求这 n 个矩形并的面积: 其中 $x \leq 10^{5} ...

  7. UVA-11983-Weird Advertisement(线段树+扫描线)[求矩形覆盖K次以上的面积]

    题意: 求矩形覆盖K次以上的面积 分析: k很小,可以开K颗线段树,用sum[rt][i]来保存覆盖i次的区间和,K次以上全算K次 // File Name: 11983.cpp // Author: ...

  8. 2015 UESTC 数据结构专题E题 秋实大哥与家 线段树扫描线求矩形面积交

    E - 秋实大哥与家 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 De ...

  9. hdu1828 线段树扫描线求矩形面积的周长

    题意:       给你n个矩形,问你这n个矩形所围成的图形的周长是多少. 思路:       线段树的扫描线简单应用,这个题目我用的方法比较笨,就是扫描两次,上下扫描,求出多边形的上下边长和,然后同 ...

随机推荐

  1. laravel composer 安装指定版本以及基本的配置

    1 安装指定的 laravel版本 以下的案例是安装5.2版本 composer create-project laravel/laravel=5.2.* --prefer-dist 2 配置 优化相 ...

  2. Spring Boot + Spring Cloud 实现权限管理系统 (集成 Shiro 框架)

    Apache Shiro 优势特点 它是一个功能强大.灵活的,优秀开源的安全框架. 它可以处理身份验证.授权.企业会话管理和加密. 它易于使用和理解,相比Spring Security入门门槛低. 主 ...

  3. lodash 学习资料

    lodash.js 是什么不多说,工作时间长了就基本绕不过去他,工作项目中也很好的弥补angular ,jquery 的不足,由中文bootstrap 退出的中文版学习资料 http://lodash ...

  4. 银联支付 Asp.Net 对接开发内容简介

    银联对接开发主要包含测试环境以及生产环境两部分. 其中程序开发部分测试以及生产是相同的. 不同的是,测试环境与生产环境请求支付的Url地址,以及分别使用的证书不同. 一.配置部分 1,测试环境证书获取 ...

  5. HTML(二)选择器

    1.id选择器 一对一关系 <div id="only">123</div> #only{ background-color:black; } 2.clas ...

  6. MATLAB图片折腾3

    把视频抽帧,转化成图片 我的代码如下,成功实现clc;clear;videofilename='k:\GraduationWork\Resource\video.wmv'; %where you pu ...

  7. 非递归实现二叉树的三种遍历操作,C++描述

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  8. 谷歌开源的TensorFlow Object Detection API视频物体识别系统实现(二)[超详细教程] ubuntu16.04版本

    本节对应谷歌开源Tensorflow Object Detection API物体识别系统 Quick Start步骤(一): Quick Start: Jupyter notebook for of ...

  9. Docker常用命令学习

    sudo service docker startsudo docker run hello-worlddocker stats --helpdocker run -d -P training/web ...

  10. Code First 迁移更新数据库

    在使用 Code First 方式进行MVC程序设计中,更新数据库操作记录: 1.修改需要更新的Model,将应用程序重新编译 2.选择工具>库程序包管理器>程序包管理控制台,打开控制台, ...