题目链接:点击打开链接

链接题目大意:给出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. (48)zabbix报警媒介:自定义脚本Custom alertscripts

    自定义脚本媒介.zabbix会将信息传递给脚本,接下来你在脚本里面随意处理,一共会传递三个参数,按顺序接受也就是$1,$2,$3了,为了方便记忆,一般分别给他们赋值到To\Subject\body 配 ...

  2. 使用dmidecode在Linux下获取硬件信息

    dmidecode命令可以让你在Linux系统下获取有关硬件方面的信息.dmidecode的作用是将DMI数据库中的信息解码,以可读的文本方式显示.由于DMI信息可以人为修改,因此里面的信息不一定是系 ...

  3. 对freescale的mfgtool的ucl2.xml的理解

    转载于此:http://blog.csdn.net/bugouyonggan/article/details/8664898 对于Freescale MFG编程工具控制文件ucl2.xml的分析 为了 ...

  4. PAT Basic 1041

    1041 考试座位号 每个 PAT 考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位.正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码 ...

  5. POJ 2955 区间DP Brackets

    求一个括号的最大匹配数,这个题可以和UVa 1626比较着看. 注意题目背景一样,但是所求不一样. 回到这道题上来,设d(i, j)表示子序列Si ~ Sj的字符串中最大匹配数,如果Si 与 Sj能配 ...

  6. appium之toast处理

    注意 toast要appium1.6.3以上版本才支持,Android 5.0以上(需使用夜神多开模拟器),jdk1.8且配置了环境变量. toast定位 1.先看下toast长什么样,如下图,像这种 ...

  7. Consecutive Subsequence (DP+map)

    You are given an integer array of length nn. You have to choose some subsequence of this array of ma ...

  8. 安卓Toast实现

    代码改变世界 Toast实现显示 // 第一个参数:当前的上下文环境.可用getApplicationContext()或this // 第二个参数:要显示的字符串.也可是R.string中字符串ID ...

  9. Python2.6.6升级2.7.3

    Python2.7替换2.6: 1.下载Python-2.7.3 #wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2 2.解压 ...

  10. BZOJ 2298: [HAOI2011]problem a【动态规划】

    Description 一次考试共有n个人参加,第i个人说:“有ai个人分数比我高,bi个人分数比我低.”问最少有几个人没有说真话(可能有相同的分数) Input 第一行一个整数n,接下来n行每行两个 ...