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. php中socket的使用 方法简介

    一.开启socket phpinfo();查看是否开启了socket扩展,否则在php.ini中开启. 二.服务器端代码的写法 <?php error_reporting(E_ALL); set ...

  2. Walle 瓦力 web部署系统

    Walle 一个web部署系统工具,可能也是个持续发布工具,配置简单.功能完善.界面流畅.开箱即用! 安装步骤: 1. git clone 首先配置成功(去百度找答案) 打开git bash命令窗口执 ...

  3. oracle之时间转换

    :取得当前日期是本月的第几周 SQL> select to_char(sysdate,'YYYYMMDD W HH24:MI:SS') from dual; TO_CHAR(SYSDATE,'Y ...

  4. canvas-画蜗牛

    <!doctype html><html lang="en"> <head> <meta charset="UTF-8" ...

  5. CodeFirst解决数据迁移问题

    CodeFirst解决数据迁移问题 分类: 数据库 设计模式 c#2013-04-24 17:56 137人阅读 评论(0) 收藏 举报 工程用的MVC + Entity Framework,根据Co ...

  6. ASP.net 前台页面通过ID获取控件

    asp.net的服务器控件的ID通常只能在服务器端很好的识别,客户端需要通过ClientID获得控件 1.通过js获得   var controlID = "<%=controlID. ...

  7. 【socket.io研究】3.手机网页间聊天核心问题

    前面我们已经说了服务器相关的一些内容,且又根据官网给出的一个例子写了一个可以聊天的小程序,但是这还远远不够呀,这只能算是应用前的准备工作.接下来,一起来考虑完善一个小的聊天程序吧. 首先,修改服务器的 ...

  8. 统计"面"要素中"点"要素的个数.

    步骤 1,创建字段 IFields /// <summary> /// 创建:"面"-"点数"的字段. /// </summary> / ...

  9. javascript "非法值"检验.

    <script type="text/javascript"> function getCoord() { var x = document.getElementByI ...

  10. JS通用表单验证函数,基于javascript正则表达式

    表单的验证在实际的开发当中是件很烦琐又无趣的事情今天在做一个小项目的时候,需要JS验证,寻找到一个比较好的东西 地址如下: http://blog.csdn.net/goodfunman/archiv ...