http://acm.hdu.edu.cn/showproblem.php?pid=1255

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 100010
using namespace std; int t,n;
double Y[maxn],X[maxn];
struct point
{
double x;
double y_up;
double y_down;
int lr;
bool operator <(const point &a) const
{
return x<a.x;
}
}p[maxn*]; struct node
{
double x;
double y_up;
double y_down;
int cover;
bool flag;
}tree[maxn*]; void build(int i,int l,int r)
{
tree[i].x=-;
tree[i].y_up=Y[r];
tree[i].y_down=Y[l];
tree[i].cover=;
tree[i].flag=true;
if(l+==r)
{
tree[i].flag=false;
return ;
}
int mid=(l+r)>>;
build(i<<,l,mid);
build(i<<|,mid,r);
} double update(int i,double l,double r,double x,int lr)
{
if(tree[i].y_down>=r||tree[i].y_up<=l) return ;
if(!tree[i].flag)
{
if(tree[i].cover>)
{
tree[i].cover+=lr;
double sum=(x-tree[i].x)*(tree[i].y_up-tree[i].y_down);
tree[i].x=x;
return sum;
}
else
{
tree[i].cover+=lr;
tree[i].x=x;
return ;
}
}
else return update(i<<,l,r,x,lr)+update(i<<|,l,r,x,lr);
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int cnt=;
for(int i=; i<=n; i++)
{
double x1,y1,x2,y2;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
p[cnt].x=x1;
p[cnt].y_down=y1;
p[cnt].y_up=y2;
p[cnt].lr=;
X[cnt]=x1;
Y[cnt++]=y1;
p[cnt].x=x2;
p[cnt].y_down=y1;
p[cnt].y_up=y2;
X[cnt]=x2;
p[cnt].lr=-;
Y[cnt++]=y2;
}
sort(Y,Y+cnt);
sort(X,X+cnt);
sort(p,p+cnt);
build(,,cnt-);
double ans=;
for(int i=; i<cnt; i++)
{
ans+=update(,p[i].y_down,p[i].y_up,p[i].x,p[i].lr);
}
printf("%.2lf\n",ans);
}
return ;
}

hdu 1255 覆盖的面积的更多相关文章

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

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

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

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

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

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

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

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

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

    题目地址:HDU 1255 这题跟面积并的方法非常像,仅仅只是须要再加一个变量. 刚開始我以为直接用那个变量即可,仅仅只是推断是否大于0改成推断是否大于1.可是后来发现了个问题,由于这个没有下放,没延 ...

  6. hdu 1255 覆盖的面积 (扫描线求矩形交)

    覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  7. HDU 1255 覆盖的面积 ( 扫描线 + 离散 求矩阵大于k次面积并 )

    覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

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

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

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

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

随机推荐

  1. 超实用--删除MYSQL中指定的数据的全部表

    作过的人都知道,重复测试数据库的苦恼. 用法:# Usage: ./script user password dbnane mysql.nixcraft.in ~~~~~~~~~~~~~ #!/bin ...

  2. [VBA]根据身份证号码计算年龄的Excel函数

    是的,昨天刚发表了一篇和Excel自定义函数有关的博客,今天又一篇,有凑数的嫌疑.但是,保存知识和传播知识本来就是写博客的初衷,所以也并不多余. 如果不知道什么是Excel自定义函数,请移步这里[1] ...

  3. c语言sizeof与strlen的区别

    #include <stdio.h> #include <stdlib.h> #include <string.h> //strlen与sizeof的区别 //st ...

  4. poj 1466 Girls and Boys(二分匹配之最大独立集)

    Description In the second year of the university somebody started a study on the romantic relations ...

  5. git 拆库 切库 切分 子目录建库

    如果git库目录是这样的: git根目录 project_a/ project_b/ ... 并且想为project_a单独创建一个代码库 # 拉一个新分支 git co -b project_a_r ...

  6. PC-CSS-多浏览器支持HTML5

    非IE:article, section, aside, hgroup, nav, header, footer, figure, figcaption {display: block;}IE:< ...

  7. HDOJ 1316 How Many Fibs?

    JAVA大数.... How Many Fibs? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  8. Live555 实战之框架简单介绍

    作者:咕唧咕唧liukun321 来自:http://blog.csdn.net/liukun321 上一篇文章简要介绍了怎样以共享库的方式交叉编译Live555,今天再来介绍live源代码框架. 先 ...

  9. [置顶] IOS7状态栏StatusBar官方标准适配方法

    IOS7状态栏StatusBar官方标准适配方法 hello,大家好,ios7正式版已经发布,相信大家都在以各种方式来适配ios7. 如果你已经下载了xcode5,正准备使用,你会发现各种布局的改变. ...

  10. Understanding Abstractions of Secure Channels 的研读