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 ...
随机推荐
- mysql:10道mysql查询语句面试题
表结构 学生表student(id,name) 课程表course(id,name) 学生课程表student_course(sid,cid,score) 创建表的sql代码 ```sql creat ...
- IE6,7,8,9还有火狐浏览器的兼容
/*FF.Opear等支持Web标准的浏览器*/#header { margin-top: 23px; margin-bottom: 23px;}/*IE6浏览器*/*ht ...
- 爬取斗图网图片,使用xpath格式来匹配内容,对请求伪装成浏览器, Referer 防跨域请求
6.21自我总结 一.爬取斗图网 1.摘要 使用xpath匹配规则查找对应信息文件 将请求伪装成浏览器 Referer 防跨域请求 2.爬取代码 #导入模块 import requests #爬取网址 ...
- Python9-day4 作业
#!/usr/bin/env python# -*- coding:utf-8 -*-# Author:Timli = ["alex", "eric", &qu ...
- LeetCode(108) Convert Sorted Array to Binary Search Tree
题目 Given an array where elements are sorted in ascending order, convert it to a height balanced BST. ...
- Mac设置命令别名
文件中添加 /Users/xxx/.bash_profile 添加别名命令: alias pull='git pull origin' 注意:等号后面不能有空格 从新读取配置文件: source ~/ ...
- 神经网络的BP推导过程
神经网络的BP推导过程 下面我们从一个简单的例子入手考虑如何从数学上计算代价函数的梯度,考虑如下简单的神经网络,该神经网络有三层神经元,对应的两个权重矩阵,为了计算梯度我们只需要计算两个偏导数即可: ...
- Leetcode 376.摆动序列
摆动序列 如果连续数字之间的差严格地在正数和负数之间交替,则数字序列称为摆动序列.第一个差(如果存在的话)可能是正数或负数.少于两个元素的序列也是摆动序列. 例如, [1,7,4,9,2,5] 是一个 ...
- 解决Linux 服务器ntpdate同步时间报错 the NTP socket is in use, exiting
错误信息: 错误原因分析: 由于 xntpd 已经绑定到了该 Socket.运行 ntpdate 时,它会首先进行广播,然后侦听端口 123. 如果 xntpd 正在运行,而有一个进程已经在侦听该端口 ...
- hdu 1907 尼姆博弈
John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...