hdu1255

求覆盖至少两次的面积,和直接求覆盖面积比,就是保证cover>1就可以了。

没有进行lazy操作,因为每一次更新伴随着询问,感觉没有必要。982MS水过。

#include <bits/stdc++.h>
#define clr(x,c) memset(x,c,sizeof(x))
using namespace std;
const int N = 20005; struct ScanLine {
double x;
double upY, downY;
int flag;
bool operator<(const ScanLine a) const {
return x < a.x;
}
ScanLine() {}
ScanLine(double x, double y1, double y2, int f) : x(x), upY(y1), downY(y2), flag(f) {}
} line[N]; double tr[N];
int cover[N];
double yy[N]; #define lson (o<<1)
#define rson (o<<1|1)
#define mid ((l+r)>>1)
int yl, yr, v; double update(int o, int l, int r)
{
if (yl > r || yr < l) return 0; if (l == r) {
cover[o] += v;
if (cover[o] > 1) return tr[o] = yy[r + 1] - yy[l];
return tr[o] = 0;
} if (yl <= mid) update(lson, l, mid);
if (yr > mid) update(rson, mid + 1, r); return tr[o] = tr[lson] + tr[rson];
} int main()
{
int n;
int t;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
int cnt = 0;
double x1, y1, x2, y2;
for (int i = 0; i < n; ++i) {
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
line[++cnt] = ScanLine(x1, y2, y1, 1);
yy[cnt] = y1;
line[++cnt] = ScanLine(x2, y2, y1, -1);
yy[cnt] = y2;
}
sort(yy + 1, yy + cnt + 1);
sort(line + 1, line + cnt + 1);
int len = unique(yy + 1, yy + cnt + 1) - yy - 1;
clr(cover, 0);
clr(tr, 0);
double ans = 0;
for (int i = 1; i < cnt; ++i) {
yl = lower_bound(yy+1, yy+len+1, line[i].downY) - yy;
yr = lower_bound(yy+1, yy+len+1, line[i].upY) - yy - 1;
v = line[i].flag;
ans += update(1, 1, len) * (line[i+1].x - line[i].x);
}
printf("%.2f\n", ans);
}
return 0;
}

扫描线专题 hdu1255的更多相关文章

  1. CCPC-Wannafly Winter Camp Day1 (Div2, onsite) A B C E F I J

    A 机器人 链接:https://www.cometoj.com/contest/7/problem/A?problem_id=92 思路: 分两大类讨论: 1. B区没有点: (1)点都在起点左边 ...

  2. HDU-1255 覆盖的面积 (扫描线)

    题目大意:给若干个矩形,统计重叠次数不为0的面积. 题目分析:维护扫描线的长度时,只需要只统计覆盖次数大于1的区间即可.这是个区间更新,不过不能使用懒标记,但是数据规模不大,不用懒惰标记仍可以AC. ...

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

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

  4. HDU1255 覆盖的面积 —— 求矩形交面积 线段树 + 扫描线 + 离散化

    题目链接:https://vjudge.net/problem/HDU-1255 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. Input输入数据的第一行是一个正整数T(1<= ...

  5. hdu1255 矩阵的交 线段树+扫描线

    /* 不是叶子节点 ,且cnt=1.注意这里,cnt=1确切的意义是什么, 应该是,可以确定,这个区间被完全覆盖了1次, 而有没有被完全覆盖两次或以上则不知道无法确定,那么怎么怎么办了, 只要加上t[ ...

  6. hdu1255扫描线计算覆盖两次面积

    总体来说也是个模板题,但是要开两个线段树来保存被覆盖一次,两次的面积 #include<iostream> #include<cstring> #include<cstd ...

  7. 2015 UESTC 数据结构专题E题 秋实大哥与家 线段树扫描线求矩形面积交

    E - 秋实大哥与家 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 De ...

  8. HDU1255 扫描线 矩形交面积 离散化

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

  9. hdu1255 扫描线,矩形重叠面积(两次以上)

    题意:       给你n个矩形,然后问你这n个矩形所组成的画面中被覆盖至少两次的面积有多大. 思路:       和1542差距并不是很大,大体上还是离散化+线段树扫面线,不同的地方就是这个题目要求 ...

随机推荐

  1. LCD显示方向

    一.ILI9341内存到显示地址的映射 本文只讨论“正常显示”,不讨论“垂直滚动显示”模式. 可以看到物理内存被两个指针访问,行指针和列指针,行指针范围从000h到013Fh,列指针范围为0000h到 ...

  2. 【Git 】$ ./gradlew idea 构建一个idea的项目

    Welcome to Git (version 1.9.5-preview20150319) Run 'git help git' to display the help index.Run 'git ...

  3. 【JPA】两种不同的实现jpa的配置方法

    两种不同的实现jpa的配置方法 第一种: com.mchange.v2.c3p0.ComboPooledDataSource datasource.connection.driver_class=co ...

  4. 成为Java GC专家(5)—Java性能调优原则

    并不是每个程序都需要调优.如果一个程序性能表现和预期一样,你不必付出额外的精力去提高它的性能.然而,在程序调试完成之后,很难马上就满足它的性能需求,于是就有了调优这项工作.无论哪种编程语言,对应用程序 ...

  5. Load a script file in sencha, supports both asynchronous and synchronous approaches

    //http://www.sencha.com/forum/showthread.php?188318-Ext.Loader.loadScriptFile-wrong-URL Ext.Loader.l ...

  6. CSS3中translate、transform和translation的区别和联系

    translate:移动,transform的一个方法               通过 translate() 方法,元素从其当前位置移动,根据给定的 left(x 坐标) 和 top(y 坐标) ...

  7. vs git .ignore

    ## Ignore Visual Studio temporary files, build results, and## files generated by popular Visual Stud ...

  8. zepto源码学习-06 touch

    先上菜,看这个模块的最后一段代码,一看就明白. ['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown', 'doubleTap', 't ...

  9. SPRING IN ACTION 第4版笔记-第六章RENDERING WEB VIEWS-004- <s:url>、<s:escapeBody>标签

    一.<s:url> <s:url>可以直接生成一个url或url变量,它会在href的基础上加上应用context 1. <a href="<s:url ...

  10. Using FireMonkey Layouts

    FireMonkey has many layout controls to choose from. Come learn the differences and how to use them t ...