题目地址:HDU 1255

这题跟面积并的方法非常像,仅仅只是须要再加一个变量。

刚開始我以为直接用那个变量即可,仅仅只是推断是否大于0改成推断是否大于1。可是后来发现了个问题,由于这个没有下放,没延迟,比方,在父节点上加了一次1,在该父节点的子节点上又加了一次1,可是这时候全部的结点仍然没有达到2的,可是实际上子节点已经达到2了。这时候能够再加一个变量。那个变量用来保存覆盖数大于等于0的情况。这种话当计算大于1的覆盖节点的时候,当推断为1的时候就要加上子节点的全部情况,由于字节点是大于0的,加上子节点的说明该父节点也是大于1的。

代码例如以下:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
int lazy[10000], cnt;
double sum[10000], c[10000], once[10000];
struct node
{
double l, r, h;
int f;
} edge[100000];
int cmp(node x, node y)
{
return x.h<y.h;
}
void add(double l, double r, double h, int f)
{
edge[cnt].l=l;
edge[cnt].r=r;
edge[cnt].h=h;
edge[cnt++].f=f;
}
void PushUp(int l, int r, int rt)
{
if(lazy[rt]>=2)
{
once[rt]=sum[rt]=c[r+1]-c[l];
}
else if(lazy[rt]==1)
{
once[rt]=c[r+1]-c[l];
if(l==r)
{
sum[rt]=0;
}
else
sum[rt]=once[rt<<1]+once[rt<<1|1];
}
else
{
if(l==r)
once[rt]=sum[rt]=0;
else
{
once[rt]=once[rt<<1]+once[rt<<1|1];
sum[rt]=sum[rt<<1]+sum[rt<<1|1];
}
}
}
void update(int ll, int rr, int x, int l, int r,int rt)
{
if(ll<=l&&rr>=r)
{
lazy[rt]+=x;
PushUp(l,r,rt);
return ;
}
int mid=l+r>>1;
if(ll<=mid) update(ll,rr,x,lson);
if(rr>mid) update(ll,rr,x,rson);
PushUp(l,r,rt);
}
int erfen(double x, int high)
{
int low=0, mid;
while(low<=high)
{
mid=low+high>>1;
if(c[mid]==x)
return mid;
else if(c[mid]>x)
high=mid-1;
else
low=mid+1;
}
}
int main()
{
int t, n, i, j, k;
double x1, x2, y1, y2, ans;
scanf("%d",&t);
while(t--)
{
ans=0;
memset(sum,0,sizeof(sum));
memset(lazy,0,sizeof(lazy));
memset(once,0,sizeof(once));
scanf("%d",&n);
k=0;
cnt=0;
for(i=0; i<n; i++)
{
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
c[k++]=x1;
c[k++]=x2;
add(x1,x2,y1,1);
add(x1,x2,y2,-1);
}
sort(edge,edge+2*n,cmp);
sort(c,c+k);
for(i=0; i<2*n-1; i++)
{
int l=erfen(edge[i].l,2*n-1);
int r=erfen(edge[i].r,2*n-1);
//printf("%d %d\n",l,r);
update(l,r-1,edge[i].f,0,2*n-1,1);
ans+=sum[1]*(edge[i+1].h-edge[i].h);
//printf("%.2lf %.2lf\n",sum[1],edge[i+1].h-edge[i].h);
}
printf("%.2lf\n",ans);
}
return 0;
}

HDU 1255 覆盖的面积(线段树+扫描线)的更多相关文章

  1. HDU 1255 覆盖的面积 (线段树+扫描线+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 题意很清楚,就是让你求矩阵之间叠加层数大于1的矩形块的面积和. 因为n只有1000,所以我离散化 ...

  2. HDU 1255 覆盖的面积 线段树+扫描线

    同 POJ1151 这次是两次 #include <iostream> #include <algorithm> #include <cstdio> #includ ...

  3. hdu 1255 覆盖的面积 (线段树处理面积覆盖问题(模板))

    http://acm.hdu.edu.cn/showproblem.php?pid=1255 覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memo ...

  4. HDU 1255 覆盖的面积(线段树面积并)

      描述 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. Input 输入数据的第一行是一个正整数T(1<=T<=100),代表测试数据的数量.每个测试数据的第一行是一个正 ...

  5. HDU 1255 覆盖的面积(线段树:扫描线求面积并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 题目大意:给你若干个矩形,让你求这些矩形重叠两次及以上的部分的面积. 解题思路:模板题,跟HDU ...

  6. hdu1255 覆盖的面积 线段树-扫描线

    矩形面积并 线段树-扫描线裸题 #include<stdio.h> #include<string.h> #include<algorithm> #include& ...

  7. HDU - 1255 覆盖的面积(线段树求矩形面积交 扫描线+离散化)

    链接:线段树求矩形面积并 扫描线+离散化 1.给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. 2.看完线段树求矩形面积并 的方法后,再看这题,求的是矩形面积交,类同. 求面积时,用被覆 ...

  8. hdu 1255 覆盖的面积(线段树 面积 交) (待整理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 Description 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积.   In ...

  9. hdu 1255 覆盖的面积(求覆盖至少两次以上的面积)

    了校赛,还有什么途径可以申请加入ACM校队?  覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

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

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

随机推荐

  1. cocos2dx使用lua和protobuf

    为了使游戏开发更加方便快捷,我继续了protobuf在lua下的尝试. socket使用的是cocos2dx集成的websocket. 先说下环境:cocos2d-x-2.2.1 + protobuf ...

  2. Android PopupWindow使用时注意

    项目中使用PopupWindown出现的坑 1.部分设备,PopWindow在Android4.0后版本,出现NullPointerException调用以下方法可解决, fixPopupWindow ...

  3. 三维卷积:全景图像Spherical CNNs(Code)

    卷积神经网络(CNN)可以很好的处理二维平面图像的问题.然而,对球面图像进行处理需求日益增加.例如,对无人机.机器人.自动驾驶汽车.分子回归问题.全球天气和气候模型的全方位视觉处理问题. 将球形信号的 ...

  4. GDB 学习

    通常使用gdb在Linux下调试C/C++程序,编译的时候加上-g选项(gcc -g ......).下面总结的是我自己经常使用(当然也有一些用的比较少)的gdb命令. (1)开始及退出 开始:gdb ...

  5. Vue实战之插件 sweetalert 的使用

    安装npm install sweetalert2@7.15.1 --save 封装 sweetalertimport swal from 'sweetalert2' export default { ...

  6. day20-面向对象基础

    目录 面向对象基础 面向过程编程与面向对象编程 面向过程编程 面向对象编程 类与对象 类 对象 定义类和对象 定制对象独有特征 对象属性查找顺序 类与对象的绑定方法 类与数据类型 对象的高度整合 面向 ...

  7. adb 命令收藏学习地址

    adb 命令相关的网页https://www.cnblogs.com/medsonk/p/8334847.htmlhttps://www.cnblogs.com/medsonk/p/6959658.h ...

  8. SVN A C D M G U R I 的含义

    A:add,新增 C:conflict,冲突 D:delete,删除 M:modify,本地已经修改 G:modify and merGed,本地文件修改并且和服务器的进行合并 U:update,从服 ...

  9. python_ 学习笔记(基础语法)

    python的注释 使用(#)对单行注释 使用('''或者""")多行注释,下面的代码肯定了python的牛逼 print("python是世界上最好的语言吗? ...

  10. MFC 多行文本显示心得

    最近在利用MFC做端口扫描器实验,其中涉及CString.char.int等之间的转换.文本框的多行显示问题.总是显示底层最新结果等问题,下面写一些我总结的相关方法. 一.CString 转  cha ...