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. Tomcat架构以及理解sever.xml

    Tomcat架构图 当用户在地址栏输入访问地址后,首先识别访问协议(假设为http),那么通过针对于http协议传输的Connector连接器,连接到tomcat的服务中,连接后开始检测Engine下 ...

  2. RHEL6.3进入单用户模式并重置root密码

    单用户模式类似于windows下的安全模式,允许root账号不输入密码直接启动并登录系统进行系统维护. 单用户模式只允许root账号登录,不允许其它用户使用ssh协议进行远程连接. 重启系统时按Ent ...

  3. Windows 右键快速运行命令行

    原文见:右键命令行 - yacper - 博客园 方法一:配置文件夹选项 1 打开人任意文件夹,[工具] --> [文件夹选项] --> [文件类型] --> [(无)资料夹] -- ...

  4. css样式图片、渐变、相关小知识

    一,background-position:(图片定位) 三种写法: 1):按%比,左上角最小(0%,0%),右下角最大(100%,%100): 2):(x,y)左上角最小(0,0),右下角最大(ma ...

  5. C#多线程实践——线程同步

    下面的表格列展了.NET对协调或同步线程动作的可用的工具:                       简易阻止方法 构成 目的 Sleep 阻止给定的时间周期 Join 等待另一个线程完成      ...

  6. django 自定用户系统 以及 Django Model 定义语法

    http://www.tuicool.com/articles/jMzIr2 django使用自己的用户系统 http://www.jianshu.com/p/c10be59aad7a Django ...

  7. Ajax实现三级联动(0520)

    查询数据库中的chinastates表,通过父级代号查询相应省市区. 实现界面: 在js页面实现三级联动 在JQuery中调用Ajax方法(引用JQuery文件一定放在最上面) 用插件的形式,创建三个 ...

  8. nvm linux命令

    nvm alias default 0.12.10 nvm alias default 0.10.24 nvm list NVM_NODEJS_ORG_MIRROR=http://npm.taobao ...

  9. CSS3控制元素排列

    需求: 将改变为. 代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...

  10. [Flask Security]当不能通过认证的时候制定跳转

    Flask Security这个插件能对用户权限进行很好的控制. 通过三个model实现: User,存放用户数据 Role,存放角色数据 User_Role.存放用户角色信息 user_datast ...