题意:求矩形面积的并

思路:

注意是[l,mid][mid,r] 这是真正的线段了

就当扫描线模板使吧~

//By SiriusRen
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define eps 1e-5
int N,tot,n,cases;
double y[666],ans=0;
struct Node{double x,y1,y2;int cover;}node[666];
struct Tree{double l,r,len;int cover;}tree[66666];
bool cmp(Node a,Node b){return a.x<b.x;}
void build(int l,int r,int pos){
tree[pos].l=y[l],tree[pos].r=y[r],tree[pos].len=tree[pos].cover=0;
if(l+1==r)return;
int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1;
build(l,mid,lson),build(mid,r,rson);
}
void push_up(int l,int r,int pos){
if(tree[pos].cover>0)
tree[pos].len=tree[pos].r-tree[pos].l;
else if(l+1==r)tree[pos].len=0;
else tree[pos].len=tree[pos<<1].len+tree[pos<<1|1].len;
}
void update(int l,int r,int pos,Node jy){
if(tree[pos].l>=jy.y1&&tree[pos].r<=jy.y2){
tree[pos].cover+=jy.cover;push_up(l,r,pos);
return;
}
int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1;
if(tree[lson].r>=jy.y2)update(l,mid,lson,jy);
else if(tree[rson].l<=jy.y1)update(mid,r,rson,jy);
else update(l,mid,lson,jy),update(mid,r,rson,jy);
push_up(l,r,pos);
}
int main(){
while(scanf("%d",&N)&&N){
ans=tot=0;
for(int i=1;i<=N;i++){
double X1,Y1,X2,Y2;
scanf("%lf%lf%lf%lf",&X1,&Y1,&X2,&Y2);
node[++tot].x=X1,node[tot].y1=Y1,node[tot].y2=Y2;node[tot].cover=1;y[tot]=Y1;
node[++tot].x=X2,node[tot].y1=Y1,node[tot].y2=Y2;node[tot].cover=-1;y[tot]=Y2;
}
sort(node+1,node+1+tot,cmp),sort(y+1,y+1+tot);
n=unique(y+1,y+1+tot)-y-1;
build(1,n,1),update(1,n,1,node[1]);
for(int i=2;i<=tot;i++){
ans+=tree[1].len*(node[i].x-node[i-1].x);
update(1,n,1,node[i]);
}
printf("Test case #%d\nTotal explored area: %.2lf\n\n",++cases,ans);
}
}

POJ 1151 线段树+扫描线的更多相关文章

  1. POJ 1151 线段树+扫描线(计算矩形面积并)

    前一篇博客有了讲解就不再叙述了 #include<cstdio> #include<cstring> #include<cmath> #include<ios ...

  2. POJ 3277 线段树+扫描线

    题意: 思路: 线段树求矩形面积的并...同 POJ 1151 //By SiriusRen #include <cstdio> #include <algorithm> us ...

  3. 线段树 扫描线 L - Atlantis HDU - 1542 M - City Horizon POJ - 3277 N - Paint the Wall HDU - 1543

    学习博客推荐——线段树+扫描线(有关扫描线的理解) 我觉得要注意的几点 1 我的模板线段树的叶子节点存的都是 x[L]~x[L+1] 2 如果没有必要这个lazy 标志是可以不下传的 也就省了一个pu ...

  4. 【POJ-2482】Stars in your window 线段树 + 扫描线

    Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11706   Accepted:  ...

  5. POJ-1151-Atlantis(线段树+扫描线+离散化)[矩形面积并]

    题意:求矩形面积并 分析:使用线段树+扫描线...因为坐标是浮点数的,因此还需要离散化! 把矩形分成两条边,上边和下边,对横轴建树,然后从下到上扫描上去,用col表示该区间有多少个下边,sum代表该区 ...

  6. 【Codeforces720D】Slalom 线段树 + 扫描线 (优化DP)

    D. Slalom time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  7. Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)

    题目链接:http://codeforces.com/contest/522/problem/D 题目大意:  给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...

  8. HDU 4419 Colourful Rectangle --离散化+线段树扫描线

    题意: 有三种颜色的矩形n个,不同颜色的矩形重叠会生成不同的颜色,总共有R,G,B,RG,RB,GB,RGB 7种颜色,问7种颜色每种颜色的面积. 解法: 很容易想到线段树扫描线求矩形面积并,但是如何 ...

  9. BZOJ-3228 棋盘控制 线段树+扫描线+鬼畜毒瘤

    3228: [Sdoi2008]棋盘控制 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 23 Solved: 9 [Submit][Status][D ...

随机推荐

  1. AIX查看某个端口被哪个进程占用

    AIX查看某个端口被哪个进程占用 学习了:https://zhidao.baidu.com/question/1928716757722021467.html 1. netstat -Aan|grep ...

  2. Nginx系列(四)--工作原理

    上篇文章介绍了Nginx框架的设计之管理进程以及多个工作进程的设计.master进程用来管理通过fork子进程与子进程通信.子进程通过处理进程信号接到master的通信去处理请求. Nginx工作原理 ...

  3. DevExpress TreeList控件的复选框

    作者:jiankunking 出处:http://blog.csdn.net/jiankunking TreeList控件能够同一时候显示树结构和其它数据列,即在一个列上建立父子关系展开或收缩,同一时 ...

  4. app-framework学习--nav的Scroller禁用与启用

    app-framewor(jqmobi) nav的Scroller禁用与启用 写在panel 的 data-load 方法里 禁用  $.ui.scrollingDivs.menu_scroller. ...

  5. validform

    一.validform是什么?            validform是一款智能的表单验证js插件,它是基于jQuery库与css,我们只需要把表单对象放入,             就可以对整个表 ...

  6. @Query Annotation in Spring Data JPA--转

    原文地址:http://javabeat.net/spring-data-jpa-query/ In my previous post on Spring Data, I have explained ...

  7. jQuery学习(五)——使用JQ完成复选框的全选和全不选

    1.在系统后台进行人员管理时,进行批量删除,使用jq完成全选和全不选 步骤分析: 第一步:引入jquery文件 第二步:书写页面加载函数 第三步:为上面的复选框绑定单击事件 第四步:将下面所有的复选框 ...

  8. 【原创】VMWare克隆或复制Linux虚拟机后无法上网的解决

    如果选择桥接,需要设置网卡通过哪个物理网卡桥接,桥接代表当前虚拟机通过本机的网卡直接连到网络中,本机网卡作为一个交换机直连.因此需要确定使用哪个网卡桥接,一般在单网卡的时候选择自动即可,多网卡时需要指 ...

  9. asp.net HTTP请求过程

    http://blog.csdn.net/zxxSsdsd/article/details/51909860

  10. Maven配置文件中配置指定JDK版本

    1. 在setting.xml文件中的<profiles>标签加入如下配置: <profile> <id>jdk-1.8</id> <activa ...