大意: 求矩形面积并.

枚举$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. Google Protobuf结合Netty实践

    1.Win版Protobuf代码生成工具下载: https://github.com/protocolbuffers/protobuf/releases 注意下载protoc-3.6.1-win32. ...

  2. Windows FindFirstFile利用

    目前大多数程序都会对上传的文件名加入时间戳等字符再进行MD5,然后下载文件的时候通过保存在数据库里的文件ID读取文件路径,一样也实现了文件下载,这样我们就无法直接得到我们上传的webshell文件路径 ...

  3. P5057 [CQOI2006]简单题(线段树)

    果然简单题,5分钟紫题++ 代码 #include <cstdio> #include <algorithm> #include <cstring> using n ...

  4. A successful Git branching model——经典篇

    A successful Git branching model In this post I present the development model that I’ve introduced f ...

  5. 原生js仿jquery一些常用方法

    原生js仿jquery一些常用方法 下面小编就为大家带来一篇原生js仿jquery一些常用方法(必看篇).小编觉得挺不错的,现在就分享给大家,也给大家做个参考.一起跟随小编过来看看吧   最近迷上了原 ...

  6. 《机器学习实战》之k-近邻算法(手写识别系统)

    这个玩意和改进约会网站的那个差不多,它是提前把所有数字转换成了32*32像素大小的黑白图,然后转换成字符图(用0,1表示),将所有1024个像素点用一维矩阵保存下来,这样就可以通过knn计算欧几里得距 ...

  7. Python学习 day01打卡

    1.Python : 是一门解释型 弱类型 高级开发编程语言. 2.第一个Python程序的编写: print ("hell,world") 3.变量:把程序运行过程中的值储存起来 ...

  8. Linux Shell脚本攻略:shell中各种括号()、(())、[]、[[]]、{}的作用

    技巧小结: 字符串比较用双中括号[[ ]]:算数比较用单中括号[ ]——左右留空格 算数运算用双小括号(( )) :shell命令及输出用小括号( )——左右不留空格 快速替换用花括号{ }——左右留 ...

  9. hdu 3836 Equivalent Sets trajan缩点

    Equivalent Sets Time Limit: 12000/4000 MS (Java/Others)    Memory Limit: 104857/104857 K (Java/Other ...

  10. Error: Program type already present: okhttp3.Authenticator$1

    在app中的build.gradle中加入如下代码, configurations { all*.exclude group: 'com.google.code.gson' all*.exclude ...