题目链接:点击打开链接

链接题目大意:给出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(扫描线)的更多相关文章

  1. 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 ...

  2. poj 2482 Stars in Your Window(扫描线)

    id=2482" target="_blank" style="">题目链接:poj 2482 Stars in Your Window 题目大 ...

  3. POJ2482 Stars in Your Window 和 test20180919 区间最大值

    Stars in Your Window Language:Default Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K T ...

  4. Poj2482 Stars in Your Window(扫描线)

    题面 Poj 题解 下面内容引用自"李煜东 <算法竞赛进阶指南>"(对原文略有缩减,侵删): 因为矩形的大小固定,所以矩形可以由它的任意一个顶点唯一确定.我们可以考虑把 ...

  5. 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 ...

  6. poj2482 Stars in Your Window

    此题可用线段树或静态二叉树来做. 考虑用线段树: 很容易想到先限定矩形横轴范围再考虑在此纵轴上矩形内物品总价值的最大值. 那么枚举矩形横轴的复杂度是O(n)的,考虑如何快速获取纵轴上的最大值. 我们不 ...

  7. 【POJ-2482】Stars in your window 线段树 + 扫描线

    Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11706   Accepted:  ...

  8. 【POJ2482】Stars in Your Window

    [POJ2482]Stars in Your Window 题面 vjudge 题解 第一眼还真没发现这题居然™是个扫描线 令点的坐标为\((x,y)\)权值为\(c\),则 若这个点能对结果有\(c ...

  9. 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 ...

  10. 【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 ...

随机推荐

  1. Web鼠标事件

    mousedown:鼠标按下 mouseup:鼠标抬起 mousemove:鼠标移动 mouseout:在父元素上绑定该事件,当鼠标从父元素或者从子元素上离开时都会触发该事件 mouseleave:和 ...

  2. 《嵌入式linux应用程序开发标准教程》笔记——6.文件IO编程

    前段时间看APUE,确实比较详细,不过过于详细了,当成工具书倒是比较合适,还是读一读这种培训机构的书籍,进度会比较快,遇到问题时再回去翻翻APUE,这样的效率可能更高一些. <嵌入式linux应 ...

  3. python--操作系统介绍,进程的创建(并发)

    一 .  操作系统的作用: 1:隐藏丑陋复杂的硬件接口,提供良好的抽象接口 2:管理.调度进程,并且将多个进程对硬件的竞争变得有序 二 多道技术: 所谓多道程序设计技术,就是指允许多个程序同时进入内存 ...

  4. NSArray 排序

    先研究一种方法 NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:]; ; i < ; i++) { ; [arr ...

  5. 杭电 5748 Bellovin

    Description Peter has a sequence  and he define a function on the sequence -- , where  is the length ...

  6. PAT Basic 1065

    1065 单身狗 “单身狗”是中文对于单身人士的一种爱称.本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱. 输入格式: 输入第一行给出一个正整数 N(≤ 50 000),是已知夫妻/伴侣 ...

  7. nw335 debian sid x86-64 -- 2 驱动的方式

    1 linux内核自带 2 realtek 提供的官方驱动 3 使用xp的驱动 4 第三方驱动(现在成功的,最好的方式)

  8. LongListSelector 控件 在 wp7 和wp8中的不同之处

    众所周知,wp8中的LongListSelector集成到了Rom中. 性能得到了提升,一些api也发生了变化. 在这里总结一下,作为分享,也作为备忘. 参考文献 Windows Phone 8 XA ...

  9. 六 、harbor使用

    1 登录harbor docker login 10.1.2.6 2 打上标签 docker tag e3a875d407cf 10.1.2.6/library/ctf3:xss01 3 push到h ...

  10. VOC Segmentation GT图像颜色表生成分析

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/52185581 PASCAL VOC图像 ...