HDU 3265 Posters

pid=3265" target="_blank" style="">题目链接

题意:给定一些矩形海报。中间有孔。求贴海报的之后的海报覆盖面积并

思路:海报一张能够分割成4个矩形。然后就是普通的矩形面积并了,利用线段树维护就可以

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; typedef long long ll; const int N = 50005; struct Node {
int l, r, len, cover;
int size() {return r - l + 1;}
} node[N * 4]; struct Line {
int l, r, y, flag;
Line() {}
Line(int l, int r, int y, int flag) {
this->l = l; this->r = r;
this->y = y; this->flag = flag;
}
} line[N * 8]; struct Rec {
int x1, y1, x2, y2;
Rec() {}
Rec(int x1, int y1, int x2, int y2) {
this->x1 = x1; this->y1 = y1;
this->x2 = x2; this->y2 = y2;
}
} rec[N * 4]; bool cmp(Line a, Line b) {
return a.y < b.y;
} int n;
int x[4], y[4]; #define lson(x) ((x<<1)+1)
#define rson(x) ((x<<1)+2) void pushup(int x) {
if (node[x].cover) node[x].len = node[x].size();
else if (node[x].l == node[x].r) node[x].len = 0;
else node[x].len = node[lson(x)].len + node[rson(x)].len;
} void build(int l, int r, int x = 0) {
node[x].l = l; node[x].r = r;
if (l == r) {
node[x].cover = node[x].len = 0;
return;
}
int mid = (l + r) / 2;
build(l, mid, lson(x));
build(mid + 1, r, rson(x));
pushup(x);
} void add(int l, int r, int v, int x = 0) {
if (l > r) return;
if (node[x].l >= l && node[x].r <= r) {
node[x].cover += v;
pushup(x);
return;
}
int mid = (node[x].l + node[x].r) / 2;
if (l <= mid) add(l, r, v, lson(x));
if (r > mid) add(l, r, v, rson(x));
pushup(x);
} int main() {
while (~scanf("%d", &n) && n) {
build(0, 50000);
int rn = 0, ln = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++)
scanf("%d%d", &x[j], &y[j]);
rec[rn++] = Rec(x[0], y[0], x[1], y[2]);
rec[rn++] = Rec(x[0], y[2], x[2], y[3]);
rec[rn++] = Rec(x[0], y[3], x[1], y[1]);
rec[rn++] = Rec(x[3], y[2], x[1], y[3]);
}
for (int i = 0; i < rn; i++) {
line[ln++] = Line(rec[i].x1, rec[i].x2, rec[i].y1, 1);
line[ln++] = Line(rec[i].x1, rec[i].x2, rec[i].y2, -1);
}
n = ln;
sort(line, line + n, cmp);
ll ans = 0;
for (int i = 0; i < n; i++) {
if (i) ans += (ll)node[0].len * (line[i].y - line[i - 1].y);
add(line[i].l, line[i].r - 1, line[i].flag);
}
printf("%lld\n", ans);
}
return 0;
}

HDU 3265 Posters(线段树)的更多相关文章

  1. HDU 3265 Posters (线段树+扫描线)(面积并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3265 给你n个中间被挖空了一个矩形的中空矩形,让你求他们的面积并. 其实一个中空矩形可以分成4个小的矩 ...

  2. poj_2528Mayor's posters(线段树)

    poj_2528Mayor's posters(线段树) 标签: 线段树 题目连接 Mayor's posters Time Limit: 1000MS Memory Limit: 65536K To ...

  3. hdu 4031 attack 线段树区间更新

    Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Subm ...

  4. hdu 4288 离线线段树+间隔求和

    Coder Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  5. hdu 3016 dp+线段树

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

  6. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  7. HDU 3265 Posters ——(线段树+扫描线)

    第一次做扫描线,然后使我对线段树的理解发生了动摇= =..这个pushup写的有点神奇.代码如下: #include <stdio.h> #include <algorithm> ...

  8. hdu 1828 Picture(线段树 || 普通hash标记)

    http://acm.hdu.edu.cn/showproblem.php?pid=1828 Picture Time Limit: 6000/2000 MS (Java/Others)    Mem ...

  9. (中等) HDU 3265 Posters , 扫描线。

    Problem Description Ted has a new house with a huge window. In this big summer, Ted decides to decor ...

随机推荐

  1. mysql常用操作 mysql备份与恢复

    先登录mysql  ==>mysql -uroot -p  查看数据库的版本 select version(); 查看有哪些库 show datases; 查看当前处于哪个库 select da ...

  2. Java:单例模式的七种写法(转载)

    第一种(懒汉,线程不安全): package Singleton; /** * @echo 2013-10-10 懒汉 线程不安全 */ public class Singleton1 { priva ...

  3. 关闭窗口(window.close)

    close()关闭窗口 用法: window.close(); //关闭本窗口 或 <窗口对象>.close(); //关闭指定的窗口 例如:关闭新建的窗口. <script typ ...

  4. vs2013+EF6+Mysql

    1.首先需要在整个项目中添加一个Model类库,在类库中引用EF 我需要在该项目下添加EF的MYSQL对象实体 首先需要引入几个相关引用,我通过NuGet来添加,如下图 接下来我需要通过ADO.NET ...

  5. Ring对象

    Ring是一个封闭的Path即起始和终止点有相同的坐标值,它有内部和外部属性.

  6. Search 和 Select比较 - 浅谈

    Search 语法: public IFeatureCursor Search (    IQueryFilter filter,    bool Recycling); Select 语法: pub ...

  7. for 迭代器遍历list map

    1.map与list区别     list是对象集合,允许对象重复. map是键值对的集合,不允许key重复 2.list 与 list<类型> list不限制类型,也就是object类型 ...

  8. XP 安装

    提供一下裝系統的詳細步驟,盡量詳細到每一步都有,希望能對樓主有所幫助,不盡之處還請樓主不吝指出!謝謝 装XP的步骤如下: 开机时,按del键, 进入bios界面,一般选左侧第二项,(Advanced ...

  9. php 之 文件上传(0523)

    如何上传图片: 上传页面: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http ...

  10. dedecms _ 当前位置问题的代码

    {dede:field name='position' runphp='yes'} $tc=" > "; $tf=split($tc,@me); $tn=count($tf) ...