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 ...
随机推荐
- VIJOS1476 旅行规划(树形Dp + DFS暴力乱搞)
题意: 给出一个树,树上每一条边的边权为 1,求树上所有最长链的点集并. 细节: 可能存在多条最长链!最长链!最长链!重要的事情说三遍 分析: 方法round 1:暴力乱搞Q A Q,边权为正-> ...
- Linux下二进制文件安装MySQL
MySQL 下载地址:https://dev.mysql.com/downloads/mysql/ 并按如下方式选择来下载安装包. 1. 设置配置文件/etc/my.cnmore /etc/my.cn ...
- Java-得到类的包
package com.tj; public class MyClass2 { public static void main(String[] args) { Class cls = java.la ...
- ZingChart 图表插件
ZingChart提供了一个丰富的API,用于通过重新绘制绘图(重新加载) ,加载新数据(setseriesdata),修改现有图表(modifyplot), 放大数据范围(zoomto),切换各种交 ...
- ubuntu14.04LTS root登录出现错误
输入root帐号和密码,出现以下错误: Error found when loading /root/.profile stdin:is not a tty 解决方法: 在终端中用命令:gedit / ...
- Ubuntu安装 Docker CE,VNC访问docker图形界面并安装ROS
从包安装 如果您无法使用Docker的存储库来安装Docker CE,则可以下载.deb适用于您的发行版的 文件并手动安装.每次要升级Docker CE时都需要下载新文件. 安装Docker CE,将 ...
- POJ 2411 Mondriaan's Dream ——状压DP 插头DP
[题目分析] 用1*2的牌铺满n*m的格子. 刚开始用到动规想写一个n*m*2^m,写了半天才知道会有重复的情况. So Sad. 然后想到数据范围这么小,爆搜好了.于是把每一种状态对应的转移都搜了出 ...
- 算法复习——LCA模板(POJ1330)
题目: Description A rooted tree is a well-known data structure in computer science and engineering. An ...
- P2085 最小函数值 (堆)
题目描述 有n个函数,分别为F1,F2,...,Fn.定义Fi(x)=Aix^2+Bix+Ci (x∈N*).给定这些Ai.Bi和Ci,请求出所有函数的所有函数值中最小的m个(如有重复的要输出多个). ...
- [ZJOI2005]午餐 (贪心,动态规划)
题目描述 上午的训练结束了,THU ACM小组集体去吃午餐,他们一行N人来到了著名的十食堂.这里有两个打饭的窗口,每个窗口同一时刻只能给一个人打饭.由于每个人的口味(以及胃口)不同,所以他们要吃的菜各 ...