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. jsp 中文乱码

    解决jsp中文乱码问题的几个步骤 1 jsp页面设置        <%@ page language="java" contentType="text/html; ...

  2. Windows系统上设置 Git Bash 的 Font 及 Locale

    在windows 上使用 Git Bash 可以获得 unix 命令 操作体验. 但是初始的Git Bash的字体及语系都很不方便,需要自己设置. 在Git Bash的命令窗体上边框点击鼠标右键可以进 ...

  3. Linux系统命令行中vim编辑器取消高亮显示

    由于在使用vim编辑代码的时候不小心忘记首先输入i(insert)模式,导致写的代码出现了棕黄色的阴影显示 摸索了很久终于找到了解决方法: 1.退出vim编译器 2.在在命令行下输入:nohl,回车 ...

  4. 5.9 C++重载转型操作符

    参考:http://www.weixueyuan.net/view/6387.html 注意: 转型构造函数可以将其它类型的参数转换为类类型,如果我们要进行相反的转换过程,将类类型转换为其它数据类型, ...

  5. vivado对task和function的可综合支持

    手册UG901,对vivado可综合的语句支持进行了描述,HDL包括:verilog-2001,system-verilog,VHDL: verilog-2001扩展了对task和function的支 ...

  6. Java作业五

    1.编程生成10个1~100之间的随机数,并统计每个数出现的概率. 这个博文里面又random的详细解释:https://www.cnblogs.com/ningvsban/p/3590722.htm ...

  7. dubbo的几种配置方式(转)

    昨天刚接触公司dubbo,发现公司中项目里面的spring-dubbo-privider的dubbo中<dubbo:application name=""/>和< ...

  8. golang fmt占位符

    golang fmt格式"占位符" golang 的fmt 包实现了格式化I/O函数,类似于C的 printf 和 scanf. 定义示例类型和变量 type Human stru ...

  9. .Net 3.5 安装教程

    虽然说.NET Framework 3.5 SP1已经不是最新版的,但是还有大部分用Xp系统的人还得用它.不过我们使用的系统一般都是Ghost版Xp,Ghost大部分都做过尽量的简化,去除了不必要的组 ...

  10. python scrapy 数据处理时间格式转换

    def show(self,response): # print(response.url) title = response.xpath('//main/div/div/div/div/h1/tex ...