大意: 求矩形面积并.

枚举$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. luogu1975 [国家集训队]排队

    思路 序列中 |i | 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| |----|--|--|--|--|--|--|--|--|--|--| |a[i]| a| b| c| L| d ...

  2. size_t和unsigned int区别

    size_t和unsigned int有所不同,size_t的取值range是目标平台下最大可能的数组尺寸,一些平台下size_t的范围小于int的正数范围,又或者大于unsigned int.最典型 ...

  3. hihoCoder week20 线段树的区间修改

    区间修改 区间查询 最后一场比赛前的无可救药的热身 #include <bits/stdc++.h> using namespace std; #define mid ((l+r)/2) ...

  4. hosts文件介绍

    在Window系统中有个Hosts文件(没有后缀名),在Windows98系统下该文件在Windows目录,在Windows2000/XP系统中位于C:\Winnt\System32\Drivers\ ...

  5. Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'zoneId' in 'class java.lang.String'

    本文为博主原创,未经允许不得而转载: 异常展示: dao层定义的接口为: public int getClientTotal(); 在mybatis中的sql为: <select id=&quo ...

  6. Linux 命令之split(将一个大文件根据行数平均分成若干个小文件)

    把一个 txt 文件导入到 excel 中,但是 excel 单列支持的行数为 1048576,而我需要导入的 txt 文件总共有 7945674 ,我们无法一次性将整个 txt 文件里面的内容导入到 ...

  7. 关于js中splice方法返回的结果

    一.前言 刚刚在使用splice()方法,发现这个方法返回的是删除后的数组元素,如果要获取删除指定元素后的数组,直接调用原来的数组即可!因为splice()会改变原来数组!之前对splice()方法一 ...

  8. str_replace 批量查找替换字符串

    <?php $str = 'I Love You!'; $str = str_replace('o','O',$str,$count); echo $str.PHP_EOL; // I LOve ...

  9. JAVA实操项目:转账接口设计

    在一个项目中,一般都会支付相关的业务,而涉及到支付必定会有转账的操作,转账这一步想起来算是比较关键的部分,这个接口的设计能力,也大致体现出一个人的水平. 昨天碰到了一个题目: 尝试用java编写一个转 ...

  10. win10 cmake编译 opencv4.0 + pyhton3.7x64

    在超极本上本来不想编译了,反正没有cuda.但发现即使下载的opencv_contrib也不包含sift等等nonfree库了,要自己编译开编译选项才可以.坑啊,自己编译吧.反正opencv已经这么庞 ...