poj2482--Stars in Your Window(扫描线)
题目链接:点击打开链接
链接题目大意:给出n个星星的坐标,每一个星星有一个亮度。给出一个矩形的长和宽,问矩形能包含的星星的最大亮度和(不包含边框)。
如果每个星星都是矩形的最左下点。那么每个星星都能够得到一个矩形,(x,y)->(x,y,x+w,y+h)。这个矩形的两条高边的值也就是星星的亮度k和-k,对于不同的矩形来说,如果高线出现重合部分,那么也就是说这两个星是能够出如今同一个矩形中的,扫描线求出可能出现的最大的亮度和。
注意:由于不包含边框,所以扫描时应先扫描值为负的高线。而且仅对值为正的高线统计最大值。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
#define LL __int64
#define lson l,(l+r)/2,rt<<1
#define rson (l+r)/2,r,rt<<1|1
#define root 1,num_y,1
#define int_rt int l,int r,int rt
struct node{
LL x , y1 , y2 ;
LL k ;
}p[30000];
LL y[30000] ;
int cnt , num_y ;
struct node1{
LL max1 , l , r , lazy ;
}cl[200000];
int cmp(node a,node b) {
return a.x < b.x || ( a.x == b.x && a.k < 0 ) ;
}
void push_up(int rt) {
cl[rt].max1 = max(cl[rt<<1].max1,cl[rt<<1|1].max1) + cl[rt].lazy;
}
void create(int_rt) {
cl[rt].max1 = cl[rt].lazy = 0 ;
cl[rt].l = y[l] , cl[rt].r = y[r] ;
if( r - l == 1 ) {
return ;
}
create(lson) ;
create(rson) ;
push_up(rt) ;
}
void update(LL ll,LL rr,LL k,int rt) {
if( cl[rt].l >= ll && cl[rt].r <= rr ) {
cl[rt].lazy += k ;
cl[rt].max1 += k ;
return ;
}
if( ll < cl[rt<<1].r )
update(ll,min(rr,cl[rt<<1].r),k,rt<<1) ;
if( rr > cl[rt<<1|1].l )
update(max(cl[rt<<1|1].l,ll),rr,k,rt<<1|1) ;
push_up(rt) ;
}
int main() {
LL n , w , h , xx , yy , k , max1 ;
int i , j ;
while( scanf("%I64d %I64d %I64d", &n, &w, &h) != EOF ) {
cnt = 0 , num_y = 1 ;
max1 = 0 ;
for(i = 1 ; i <= n ; i++) {
scanf("%I64d %I64d %I64d", &xx, &yy, &k) ;
p[cnt].x = xx ; p[cnt].y1 = yy ; p[cnt].y2 = yy+h ;
p[cnt++].k = k ;
p[cnt].x = xx+w ; p[cnt].y1 = yy ; p[cnt].y2 = yy+h ;
p[cnt++].k = -k ;
y[num_y++] = yy ;
y[num_y++] = yy+h ;
}
sort(y+1,y+num_y) ;
num_y = unique(y+1,y+num_y) - (y+1) ;
sort(p,p+cnt,cmp) ;
create(root) ;
for(i = 0 ; i < cnt ; i++) {
update(p[i].y1,p[i].y2,p[i].k,1) ;
if( p[i].k > 0 )
max1 = max(max1,cl[1].max1) ;
}
printf("%I64d\n", max1) ;
}
return 0 ;
}
poj2482--Stars in Your Window(扫描线)的更多相关文章
- POJ2482 Stars in Your Window(扫描线+区间最大+区间更新)
Fleeting time does not blur my memory of you. Can it really be 4 years since I first saw you? I stil ...
- poj 2482 Stars in Your Window(扫描线)
id=2482" target="_blank" style="">题目链接:poj 2482 Stars in Your Window 题目大 ...
- POJ2482 Stars in Your Window 和 test20180919 区间最大值
Stars in Your Window Language:Default Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K T ...
- Poj2482 Stars in Your Window(扫描线)
题面 Poj 题解 下面内容引用自"李煜东 <算法竞赛进阶指南>"(对原文略有缩减,侵删): 因为矩形的大小固定,所以矩形可以由它的任意一个顶点唯一确定.我们可以考虑把 ...
- POJ2482 Stars in Your Window 题解
Fleeting time does not blur my memory of you. Can it really be 4 years since I first saw you? I stil ...
- poj2482 Stars in Your Window
此题可用线段树或静态二叉树来做. 考虑用线段树: 很容易想到先限定矩形横轴范围再考虑在此纵轴上矩形内物品总价值的最大值. 那么枚举矩形横轴的复杂度是O(n)的,考虑如何快速获取纵轴上的最大值. 我们不 ...
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- 【POJ2482】Stars in Your Window
[POJ2482]Stars in Your Window 题面 vjudge 题解 第一眼还真没发现这题居然™是个扫描线 令点的坐标为\((x,y)\)权值为\(c\),则 若这个点能对结果有\(c ...
- POJ 2482 Stars in Your Window 线段树扫描线
Stars in Your Window Description Fleeting time does not blur my memory of you. Can it really be 4 ...
- 【POJ2482】【线段树】Stars in Your Window
Description Fleeting time does not blur my memory of you. Can it really be 4 years since I first saw ...
随机推荐
- 使用dmidecode在Linux下获取硬件信息
dmidecode命令可以让你在Linux系统下获取有关硬件方面的信息.dmidecode的作用是将DMI数据库中的信息解码,以可读的文本方式显示.由于DMI信息可以人为修改,因此里面的信息不一定是系 ...
- Spring中使用注解 @Scheduled 执行定时任务
来自:http://blog.51cto.com/dwf07223/1557145 注解@Scheduled 可以作为一个触发源添加到一个方法中,例如,以下的方法将以一个固定延迟时间5秒钟调用一次执行 ...
- 我的Python分析成长之路2
2018-12-29 一.python数据类型: 1.数字 int(整形) float(浮点型) complex(复数型) 2.布尔值(bool) 真或假 True or False 3.字符 ...
- shell-code-4-运算符
#1. shell 基本运算符有:算数.关系.布尔.字符串.文件测试运算符#2. 原生bash不支持简单的数学运算,可使用awk和expr(最常用)echo `expr 1 + 2`# 反引号:表达式 ...
- H5系列之地理位置(必知必会)
H5之地理位置必知必会 [02]概念 规范地址:http://www.w3.org/TR/geolocation-API/ HTML5 Geolocation(地理定位)用于定位用 ...
- js 获取json对象的Key、value
<script type="text/javascript"> getJson('age'); function getJson(key){ var jsonObj={ ...
- centos 7安装libreoffice
centos 7安装libreoffice Centos下的LibreOffice安装: 关键字: LibreOffice , sdk ,汉化 ,解压 安装Centos7之后,系统安装了libreo ...
- 【java 基础 9】原来我从没有了解过String类
导读:这两天没有做项目,然后就想着把之前在项目中用到过的东西总结总结.记得之前做今日开讲项目时,在比较学生学号的时候,我最开始用的是"==",但是,实践证明,这个玩意儿吧,总是很奇 ...
- 九度oj题目1008:最短路径问题
题目描述: 给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点t,要求输出起点到终点的最短距离及其花费,如果最短距离有多条路线,则输出花费最少的. 输入: ...
- caffe+vs2013+window10+GPU(CPU)配置
参考:http://www.echojb.com/cuda/2017/03/15/350138.html https://www.zhihu.com/question/56111727 第一步:首先确 ...