HDU 1542 Atlantis(线段树面积并)
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.
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.
10 10 20 20
15 15 25 25.5
0
Total explored area: 180.00
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int N=; int col[N<<];
double sum[N<<],x[N<<]; struct seg
{
double l,r,h;
int s;
seg(){}
seg(double l,double r,double h,int s):l(l),r(r),h(h),s(s){}
bool operator<(const seg &D)const{
return h<D.h;
}
}s[N];
void PushUp(int rt,int l,int r)
{
if(col[rt])sum[rt]=x[r+]-x[l];
else if(l==r)sum[rt]=;
else sum[rt]=sum[rt<<]+sum[rt<<|];
}
void Update(int L,int R,int C,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
col[rt]+=C;
PushUp(rt,l,r);
return;
}
int mid=(l+r)>>;
if(L<=mid)Update(L,R,C,l,mid,rt<<);
if(R>mid)Update(L,R,C,mid+,r,rt<<|);
PushUp(rt,l,r);
}
int main()
{
int n,o=;
double a,b,c,d;
while(~scanf("%d",&n),n)
{
int cnt=;
for(int i=;i<n;i++)
{
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
s[++cnt]=seg(a,c,b,);
x[cnt]=a;
s[++cnt]=seg(a,c,d,-);
x[cnt]=c;
}
sort(x+,x++cnt);
sort(s+,s++cnt);
int k=;
for(int i=;i<=cnt;i++)
if(x[i]!=x[i-])
x[++k]=x[i]; memset(sum,,sizeof sum);
memset(col,,sizeof col);
double ans=;
for(int i=;i<cnt;i++)
{
int l=lower_bound(x+,x++k,s[i].l)-x;
int r=lower_bound(x+,x++k,s[i].r)-x-;
Update(l,r,s[i].s,,k,);
ans+=sum[]*(s[i+].h-s[i].h);
}
printf("Test case #%d\nTotal explored area: %.2f\n\n",o++,ans);
}
return ;
}
HDU 1542 Atlantis(线段树面积并)的更多相关文章
- POJ 1151 / HDU 1542 Atlantis 线段树求矩形面积并
题意:给出矩形两对角点坐标,求矩形面积并. 解法:线段树+离散化. 每加入一个矩形,将两个y值加入yy数组以待离散化,将左边界cover值置为1,右边界置为2,离散后建立的线段树其实是以y值建的树,线 ...
- HDU 1542 - Atlantis - [线段树+扫描线]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- hdu 1542 Atlantis(线段树,扫描线)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- hdu 1542 Atlantis (线段树扫描线)
大意: 求矩形面积并. 枚举$x$坐标, 线段树维护$[y_1,y_2]$内的边是否被覆盖, 线段树维护边时需要将每条边挂在左端点上. #include <iostream> #inclu ...
- HDU 1542 Atlantis (线段树 + 扫描线 + 离散化)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 1542 Atlantis(矩形面积并)
HDU 1542 Atlantis 题目链接 题意:给定一些矩形,求面积并 思路:利用扫描线,因为这题矩形个数不多,直接暴力扫就能够了.假设数据大.就要用线段树 代码: #include <cs ...
- hdu 1542 Atlantis(段树&扫描线&面积和)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 1542 Atlantics 线段树+离散化扫描
将 x 轴上的点进行离散化,扫描线沿着 y 轴向上扫描 每次添加一条边不断找到当前状态有效边的长度 , 根据这个长度和下一条边形成的高度差得到一块合法的矩形的面积 #include<iostre ...
- Atlantis HDU - 1542 (线段树扫描线)
There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...
随机推荐
- 常用jqueryPlugin
http://www.jq22.com editable-select : jQuery可编辑可下拉插件jquery.editable-select.js
- TCP 协议相关
TCP特点: 提供可靠的,保证数据能够准确的到达目的地,如果不能,需要检测发现并重传 流量可控,管理发送数据的频率,不超过设备的承载能力 滑动窗口:https://blog.csdn.net/wdsc ...
- 腾讯助理PHP开发工程师外包岗面经
校招错过腾讯了,在社招上看到腾讯有招外包岗,要求比正式岗低,于是抱着试一试的心态投了简历,没一会就收到了笔试题,还算简单. 第二天收到面试官的面试邀请,然后去面试了…… 腾讯里面真是漂亮,光是看装潢就 ...
- cin.tie与sync_with_stdio加速输入输出
在LeetCode上练习习题的时候每次AC之后都会去看别人的代码,几乎每次都能遇到cin.tie与sync_with_stdio.类似这样: static auto x = [](){ std::io ...
- C++多态,虚函数,虚函数表,纯虚函数
1.多态性 指相同对象收到不同消息或不同对象收到相同消息时产生不同的实现动作. C++支持两种多态性:编译时多态性,运行时多态性. a.编译时多态性:通过重载函数实现 ,模板(2次编译) ...
- [Shell]一张图知道Shell(图)
- 为tomcat配置项目必须的引擎文件
1.如下图所示,红框圈出来的四个语音引擎文件是直接放在项目根目录下的,这样的话我们发布web应用的时候,项目并不能自动把这几个文件打包到tomcat中, 除非放到WebRoot文件夹下,但是这样的话项 ...
- Structs复习 简单数据校验
jar包 web.XML <?xml version="1.0" encoding="UTF-8"?> <web-app version=&q ...
- 3Ds Max 2014
原文地址:https://blog.csdn.net/u011518678/article/details/50764835 1.3Ds Max 2014 的安装和激活 激活地址: https://j ...
- ADO.Net 数据库修改
数据库的修改方法和增加一样,只是把增加语句换成了修改语句,后面执行语句是相同的 首先也是需要获取并接收输入的要修改的哪个数据以及修改后的数据 代码演示: using System; using Sys ...