大意: 求矩形面积并.

枚举$x$坐标, 线段树维护$[y_1,y_2]$内的边是否被覆盖, 线段树维护边时需要将每条边挂在左端点上.

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head const int N = 1e3+10;
int n, cas, cnt, tot;
struct _ {double l,r,h;int v;} e[N];
double b[N], sum[N<<2];
int tag[N<<2];
void pu(int o, int l, int r) {
if (tag[o]) sum[o] = b[r+1]-b[l];
else sum[o] = sum[lc]+sum[rc];
}
void update(int o, int l, int r, int ql, int qr, int v) {
if (ql<=l&&r<=qr) return tag[o]+=v,pu(o,l,r);
if (mid>=ql) update(ls,ql,qr,v);
if (mid<qr) update(rs,ql,qr,v);
pu(o,l,r);
}
void work() {
cnt=tot=0;
memset(sum,0,sizeof sum);
memset(tag,0,sizeof tag);
REP(i,1,n) {
double x1, y1, x2, y2;
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
e[++cnt]={y1,y2,x1,1};
e[++cnt]={y1,y2,x2,-1};
b[++tot]=y1,b[++tot]=y2;
}
sort(b+1,b+1+tot),tot=unique(b+1,b+1+tot)-b-1;
sort(e+1,e+1+cnt,[](_ a,_ b){return a.h<b.h;});
double ans = 0;
REP(i,1,cnt-1) {
int l=lower_bound(b+1,b+1+tot,e[i].l)-b;
int r=lower_bound(b+1,b+1+tot,e[i].r)-b-1;
update(1,1,tot,l,r,e[i].v);
ans += sum[1]*(e[i+1].h-e[i].h);
}
printf("Test case #%d\nTotal explored area: %.2lf\n\n",++cas,ans);
}
int main() {
for (; scanf("%d", &n), n; ) work();
}

hdu 1542 Atlantis (线段树扫描线)的更多相关文章

  1. HDU 1542 - Atlantis - [线段树+扫描线]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  2. HDU 1542 Atlantis (线段树 + 扫描线 + 离散化)

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  3. hdu 1542 Atlantis(线段树,扫描线)

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  4. HDU 1542 Atlantis(线段树面积并)

     描述 There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. S ...

  5. POJ 1151 / HDU 1542 Atlantis 线段树求矩形面积并

    题意:给出矩形两对角点坐标,求矩形面积并. 解法:线段树+离散化. 每加入一个矩形,将两个y值加入yy数组以待离散化,将左边界cover值置为1,右边界置为2,离散后建立的线段树其实是以y值建的树,线 ...

  6. Atlantis HDU - 1542 (线段树扫描线)

    There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...

  7. hdu 1542(线段树+扫描线 求矩形相交面积)

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  8. hdu 1542 Atlantis(段树&amp;扫描线&amp;面积和)

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  9. hdu1542 Atlantis 线段树--扫描线求面积并

    There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...

随机推荐

  1. 真心觉得没有必要使用dock和kde桌面

    在安装了, 并使用cairo-dock后, 如果不使用 cairo-dock(fallback mode) 或不启用硬件加速, 将导致 cpu的使用率一直是100%, 而且风扇响的太厉害. 说明doc ...

  2. Module controller in JMeter

    https://qualibrate.com/blog/quality-assurance/jmeter-module-controller/ 通过组合Test Fragments 和Module C ...

  3. Katana的WebAPI集成Swagger 解决方案

    这位大哥写的博客很清楚了,我就不重复了. http://www.cnblogs.com/caodaiming/p/4156476.html 错误解决 http://blog.csdn.net/gold ...

  4. python学习 day06打卡

    今天学习的主要内容是: 一,小数据池 代码块的概念 python程序是由代码块构成的,一个代码块的文本作为python程序执行的单元. 代码块:一个模块,一个函数,一个类,甚至每一个command命令 ...

  5. MInio python

    # Install Minio library. # $ pip install minio # # Import Minio library. from minio import Minio # I ...

  6. vue中click阻止事件冒泡,防止触发另一个事件

    在使用el-upload组件时,在其中放置了一个删除按钮的图片. 当点击图片,本想只删除上传的视频,但是意外触发了el-upload中的事件 解决办法:用stop,结果只删除当前预览,不触发上传事件. ...

  7. Redux基础使用

    Redux基础使用: 简介:这里是从需求来响应的执行操作redux,所以理解起来更加的容易铭记在心的三点:action/reducer/store 除此之外就是react/react native的基 ...

  8. 【二】jquery之基础概念与jquery对象与dom对象的区别及混合使用

    一:jquery基本概念 1.jquery是一个javascript框架,它是一个轻量级的js库 2.当下流行的js库有: jquery MooTools Prototype 3.$(ducoment ...

  9. 【三十四】thinkphp之curd操作

    1.数据创建(create) 接受提交过来的数据,比如表单提交的 POST(默认)数据.接受到数据后,还可以对数据进行有效的验证.完成.生成等工作 // 这里 create()方法就是数据创建,数据的 ...

  10. python的json模块的dumps,loads,dump,load方法介绍

    dumps和loads方法都在内存中转换, dump和load的方法会多一个步骤,dump是把序列化后的字符串写到一个文件中,而load是从一个文件中读取字符串 将列表转为字符串 >>&g ...