HDU 3265 Posters ——(线段树+扫描线)
第一次做扫描线,然后使我对线段树的理解发生了动摇= =。。这个pushup写的有点神奇。代码如下:
#include <stdio.h>
#include <algorithm>
#include <string.h>
#define t_mid (l+r>>1)
#define ls (o<<1)
#define rs (o<<1|1)
#define lson ls,l,t_mid
#define rson rs,t_mid+1,r
using namespace std;
const int N = + ;
const int MAXN = + ;
typedef long long ll; struct seg
{
int x1,x2,y,d;
bool operator < (const seg & temp) const
{
// 先加边后减边,这样的话就不会出现lazy[o] < 0的情况了
return y == temp.y ? d > temp.d : y < temp.y;
}
}g[N*];
int n,tot,c[MAXN<<],lazy[MAXN<<]; void add(int x1,int x2,int y,int d)
{
tot ++;
g[tot] = {x1,x2,y,d};
}
void read()
{
tot = ;
for(int i=;i<=n;i++)
{
int x1, y1, x2, y2, x3, y3, x4, y4;
scanf("%d%d%d%d%d%d%d%d",&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
if(x1 != x3)
{
add(x1,x3,y1,);
add(x1,x3,y2,-);
}
if(x4 != x2)
{
add(x4,x2,y1,);
add(x4,x2,y2,-);
}
add(x3,x4,y1,);
add(x3,x4,y3,-);
add(x3,x4,y4,);
add(x3,x4,y2,-);
}
sort(g+,g++tot);
} void up(int o) {c[o] = c[ls] + c[rs];}
/*void down(int o,int l,int r)
{
if(l == r) return ;
int len = r - l + 1;
if(lazy[o])
{
lazy[ls] = lazy[rs] = lazy[o];
if(lazy[o] > 0)
{
c[ls] = len - len / 2;
c[rs] = len / 2;
}
else
{
c[ls] = c[rs] = 0;
}
lazy[o] = 0;
}
}*/ void pushup(int o,int l,int r)
{
if(lazy[o] > )
{
//if(lazy[o] < 0) for(int i=1;i<=1000000000000LL;i++);
// 注意seg的排序规则!
c[o] = r - l + ;
}
else
{
// lazy[o] == 0
if(l == r) c[o] = ;
else up(o);
}
}
void update(int o,int l,int r,int ql,int qr,int f)
{
if(l == ql && r == qr)
{
lazy[o] += f;
pushup(o,l,r);
return ;
}
if(qr <= t_mid) update(lson,ql,qr,f);
else if(ql > t_mid) update(rson,ql,qr,f);
else
{
update(lson,ql,t_mid,f);
update(rson,t_mid+,qr,f);
}
pushup(o,l,r);
} void solve()
{
ll ans = ;
memset(c,,sizeof(c));
memset(lazy,,sizeof(lazy));
for(int i=;i<=tot;)
{
int j = i;
while(j <= tot && g[j].y == g[i].y) j++;
for(int k=i;k<j;k++) update(,,MAXN,g[k].x1+,g[k].x2,g[k].d);
if(j <= tot) ans += (ll)(c[])*(g[j].y-g[i].y);
i = j;
}
printf("%I64d\n",ans);
} int main()
{
while(scanf("%d",&n) == && n)
{
read();
solve();
}
return ;
}
HDU 3265 Posters ——(线段树+扫描线)的更多相关文章
- HDU 3265 Posters (线段树+扫描线)(面积并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3265 给你n个中间被挖空了一个矩形的中空矩形,让你求他们的面积并. 其实一个中空矩形可以分成4个小的矩 ...
- HDU 1542 - Atlantis - [线段树+扫描线]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- 覆盖的面积 HDU - 1255 (线段树-扫描线)模板提
给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. Input输入数据的第一行是一个正整数T(1<=T<=100),代表测试数据的数量.每个测试数据的第一行是一个正整数N(1& ...
- HDU 1542 Atlantis (线段树 + 扫描线 + 离散化)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- hdu 1542 Atlantis (线段树扫描线)
大意: 求矩形面积并. 枚举$x$坐标, 线段树维护$[y_1,y_2]$内的边是否被覆盖, 线段树维护边时需要将每条边挂在左端点上. #include <iostream> #inclu ...
- HDU 1828 Picture (线段树+扫描线)(周长并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1828 给你n个矩形,让你求出总的周长. 类似面积并,面积并是扫描一次,周长并是扫描了两次,x轴一次,y ...
- HDU 1828 Picture (线段树:扫描线周长)
依然是扫描线,只不过是求所有矩形覆盖之后形成的图形的周长. 容易发现,扫描线中的某一条横边对答案的贡献. 其实就是 加上/去掉这条边之前的答案 和 加上/去掉这条边之后的答案 之差的绝对值 然后横着竖 ...
- Atlantis HDU - 1542 (线段树扫描线)
There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...
- hdu 1542(线段树+扫描线 求矩形相交面积)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- HDU 3265 Posters(线段树)
HDU 3265 Posters pid=3265" target="_blank" style="">题目链接 题意:给定一些矩形海报.中间有 ...
随机推荐
- php类于对象
类与对象是面向对象程序设计的一个基本概念,类就是指某一类东西,而对象就是某一个类的具体实例 比如:黑帮是一个类,那陈浩南就是这个类的一个对象 再比如:人是一个类,那张三就是这个类的一个具体的对象 ph ...
- 笔记一:OOAD与UML
一.面向对象的概念与方法 1. 面向对象 1.1. 面向对象是一种系统建模技术 1.2. 面向对象编程是按照OO的方法学来开发程序的过程 1.3. 通过分析系统内对象的交互来描述或建模一个系统 1. ...
- android activity中监听View测量完成的4种方式
在开发中经常碰到需要在activity初始化完成后获得控件大小的情况. 但是这个操作我们不能在oncreate.onresume等生命周期方法中调用,因为我们不知道何时view才能初始化完成 为此,特 ...
- Oracle Day3 多行函数、多表查询
1.多行函数 Sum avg max min count 组函数具有滤空的作用(添加nvl屏蔽该功能) 分组group by 多行分组 分组过滤 where 和分组过滤的区别(having) 分组的增 ...
- 3.Perl 多线程:Threads(exit thread_only)
还可以在导入threads模块时设置: use threads ('exit' => 'thread_only');
- php fsockopen例子
<?php /* * 短信相关api */ class Webcall { protected $VCC_CODE; //api的账号 protected $password; //api的密码 ...
- 编译使用luasocket
编译lua5.1: 因为luasocket使用的是lua5.1,所以先下载lua5.1,编译,并把头文件和dll放在xxx/lua5.1/include和xxx/lua5.1/lib 编译luasoc ...
- hdu_5773_The All-purpose Zero(LIS)
题目链接:hdu_5773_The All-purpose Zero 题意: 给你一串数,让你求LIS,不过这里的0可以改变为任意数 题解: 官方题解讲的很清楚 1010 The All-purpos ...
- servlet第2讲(下集)----创建servlet实例(继承HttpServlet)
- android动态添加TextView或者ImageView
动态添加 text1=new TextView(this); text1.setText("动态添加"); ((LinearLayout) this.findViewById(R. ...