HDU 1255 覆盖的面积(线段树面积并)
Input
注意:本题的输入数据较多,推荐使用scanf读入数据.
5
1 1 4 2
1 3 3 7
2 1.5 5 4.5
3.5 1.25 7.5 4
6 3 10 7
3
0 0 1 1
1 0 2 1
2 0 3 1
0.00
#include<stdio.h>
#include<string.h>
#include<algorithm> using namespace std; const int N=;
int col[N<<];
double sum1[N<<],sum2[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){
return h<D.h;
}
}a[N]; void PushUp(int rt,int l,int r)
{
if(col[rt])sum1[rt]=x[r+]-x[l];
else if(l==r)sum1[rt]=;
else sum1[rt]=sum1[rt<<]+sum1[rt<<|]; if(col[rt]>=)sum2[rt]=x[r+]-x[l];
else if(l==r)sum2[rt]=;
else if(col[rt]==)sum2[rt]=sum1[rt<<]+sum1[rt<<|];
else if(col[rt]==)sum2[rt]=sum2[rt<<]+sum2[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 t;
scanf("%d",&t);
while(t--)
{
int n,cnt=;
double x1,x2,y1,y2;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
a[++cnt]=seg(x1,x2,y1,);
x[cnt]=x1;
a[++cnt]=seg(x1,x2,y2,-);
x[cnt]=x2;
}
sort(x+,x++cnt);
sort(a+,a++cnt);
int k=;
for(int i=;i<=cnt;i++)
if(x[i]!=x[i-])
x[++k]=x[i];
memset(col,,sizeof(col));
memset(sum1,,sizeof(sum1));
memset(sum2,,sizeof(sum2));
double ans=;
for(int i=;i<cnt;i++)
{
int l=lower_bound(x+,x++k,a[i].l)-x;
int r=lower_bound(x+,x++k,a[i].r)-x-;
Update(l,r,a[i].s,,k,);
ans+=sum2[]*(a[i+].h-a[i].h);
}
printf("%.2f\n",ans);
}
return ;
}
HDU 1255 覆盖的面积(线段树面积并)的更多相关文章
- hdu 1255 覆盖的面积(线段树 面积 交) (待整理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 Description 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. In ...
- HDU - 1255 覆盖的面积(线段树求矩形面积交 扫描线+离散化)
链接:线段树求矩形面积并 扫描线+离散化 1.给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. 2.看完线段树求矩形面积并 的方法后,再看这题,求的是矩形面积交,类同. 求面积时,用被覆 ...
- 线段树扫描线(一、Atlantis HDU - 1542(覆盖面积) 二、覆盖的面积 HDU - 1255(重叠两次的面积))
扫描线求周长: hdu1828 Picture(线段树+扫描线+矩形周长) 参考链接:https://blog.csdn.net/konghhhhh/java/article/details/7823 ...
- hdu 1255 覆盖的面积(求覆盖至少两次以上的面积)
了校赛,还有什么途径可以申请加入ACM校队? 覆盖的面积 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1542 Atlantis(线段树面积并)
描述 There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. S ...
- HDU 3016 Man Down (线段树+dp)
HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- HDU.5692 Snacks ( DFS序 线段树维护最大值 )
HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- HDU.1166 敌兵布阵 (线段树 单点更新 区间查询)
HDU.1166 敌兵布阵 (线段树 单点更新 区间查询) 题意分析 加深理解,重写一遍 代码总览 #include <bits/stdc++.h> #define nmax 100000 ...
随机推荐
- 检查nginx后端real server脚本,实现发现宕机剔除,恢复服务自动加入功能
#!/bin/bash #Author: Liang WeiCheng ip_array=($(grep "server 10.112.84" /etc/nginx/nginx.c ...
- elasticsearch-ik
因lucene默认采用英文且英文通过空格就可以断句.而中文则是词组,如果不加载中文词库或插件则会变为一个一个字而非词组,因此需要加载中文词库. 不加分词库所看到的中文分词效果. post _analy ...
- 人脸识别68个点<转>
[Opencv] 于仕琪 人脸68个特征点分布情况 // 鼻尖 30 // 鼻根 27 // 下巴 8 // 左眼外角 36 // 左眼内角 39 // 右眼外角 45 // 右眼内角 42 // 嘴 ...
- P12, cer, provisioning profile
p12,本地私钥(实际上证书和私钥可以一起导出成p12,这里我们仅指私钥) cer,证书,即苹果签名后的公钥 provisioning profile描述文件 一个证书对应一个私钥,也就是本地的p12 ...
- Web安全颜色
Web安全色产生的原因 不同的平台(Mac.PC等)有不同的调色板,不同的浏览器也有自己的调色板.这就意味着对于一幅图,显示在Mac上的Web浏览器中的图像,与它在PC上相同浏览器中显示的效果可能差别 ...
- redisclient can not connect
假如采用传统请执行一下命令: systemctl stop firewalld systemctl mask firewalld 并且安装iptables-services: yum install ...
- Pandas统计分析
Pandas统计分析 pandas数据的基本统计分析 和numpy的函数近似 dates = pd.date_range(',periods=10) dates df = pd.DataFrame(n ...
- poj2480-Longge's problem-(欧拉函数)
Longge is good at mathematics and he likes to think about hard mathematical problems which will be s ...
- .html() 与.text() 获取值、取值 区别
1.html代码<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <t ...
- 消息队列RabbitMQ与Spring
1.RabbitMQ简介 RabbitMQ是流行的开源消息队列系统,用erlang语言开发.RabbitMQ是AMQP(高级消息队列协议)的标准实现. 官网:http://www.rabbitmq.c ...