题意:二维平面上给你N颗星,给出星星的坐标,亮度; 然后给你一个W*H的窗口,问你最大的亮度和。

思路:扫描线,假设有一个inf*H的窗口,按照y排序,那么就把H范围内的星星放入了这个窗口(单调队列实现),现在就成了华东窗口问题,在一维数组里面找长度为W的窗口的最大和,但是现在带修改,单点修改,固定区间查询,怎么做呢? 和学生讨论了一下,常规的很难实现。 我们需要转化一下,把单点修改转化为区间修改,然后单点查询最大值。    如果x处插入L,则[x,Rx]区间加x。 ans=max(mx[1]);

(可以出一道,待修改的滑动窗口问题。

#include<iostream>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
struct in{
int x,y,l;
bool friend operator <(in w,in v){
return w.y<v.y;
}
}s[maxn];
int ans,W,H,lazy[maxn],mx[maxn];
int b[maxn],tot,p[maxn];
void pushdown(int Now)
{
if(!lazy[Now]) return ;
lazy[Now<<]+=lazy[Now]; lazy[Now<<|]+=lazy[Now];
mx[Now<<]+=lazy[Now]; mx[Now<<|]+=lazy[Now];
lazy[Now]=;
}
void add(int Now,int L,int R,int l,int r,int val)
{
if(l<=L&&r>=R){
mx[Now]+=val;
lazy[Now]+=val;
return ;
}
pushdown(Now); int Mid=(L+R)>>;
if(l<=Mid) add(Now<<,L,Mid,l,r,val);
if(r>Mid) add(Now<<|,Mid+,R,l,r,val);
mx[Now]=max(mx[Now<<],mx[Now<<|]);
}
int main()
{
int T,N;
while(~scanf("%d%d%d",&N,&W,&H)){
ans=; tot=;
rep(i,,N) scanf("%d%d%d",&s[i].x,&s[i].y,&s[i].l);
sort(s+,s+N+);
rep(i,,N<<) lazy[i]=mx[i]=;
rep(i,,N) b[++tot]=s[i].x;
sort(b+,b+N+);
tot=unique(b+,b+N+)-(b+);
rep(i,,N) s[i].x=lower_bound(b+,b+tot+,s[i].x)-b;
int R=;
rep(i,,tot) {
while(R+<=tot&&b[R+]-b[i]+<=W) R++;
p[i]=R;
}
for(int i=,j=;i<=N;i++){
add(,,tot,s[i].x,p[s[i].x],s[i].l);
while(j<=i&&s[i].y-s[j].y+>H) {
add(,,tot,s[j].x,p[s[j].x],-s[j].l);
j++;
}
ans=max(ans,mx[]);
}
printf("%d\n",ans);
}
return ;
}

POJ - 2482:Stars in Your Window (扫描线 )的更多相关文章

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

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

  2. POJ 2482 Stars in Your Window(线段树)

    POJ 2482 Stars in Your Window 题目链接 题意:给定一些星星,每一个星星都有一个亮度.如今要用w * h的矩形去框星星,问最大能框的亮度是多少 思路:转化为扫描线的问题,每 ...

  3. poj 2482 Stars in Your Window + 51Nod1208(扫描线+离散化+线段树)

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

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

  5. (中等) POJ 2482 Stars in Your Window,静态二叉树。

    Description Here comes the problem: Assume the sky is a flat plane. All the stars lie on it with a l ...

  6. POJ 2482 Stars in Your Window(扫描线+线段树)

    [题目链接] http://poj.org/problem?id=2482 [题目大意] 给出一些点的二维坐标和权值,求用一个长H,宽W的矩形能框住的最大权值之和, 在矩形边缘的点不计算在内 [题解] ...

  7. POJ 2482 Stars in Your Window (线段树区间合并+扫描线)

    这题开始一直被矩形框束缚了,想法一直都是枚举线,但是这样枚举都需要O(n^2)...但是看了别人的思路,感觉这题思想真心很好(PS:开头好浪漫的描述啊,可惜并没有什么用)  题意就是在平面上给你一些星 ...

  8. POJ 2482 Stars in Your Window (线段树+扫描线+区间最值,思路太妙了)

    该题和 黑书 P102 采矿 类似 参考链接:http://blog.csdn.net/shiqi_614/article/details/7819232http://blog.csdn.net/ts ...

  9. poj 2482 Stars in Your Window (线段树扫描线)

    题目大意: 求一个窗体覆盖最多的星星的权值. 思路分析: 每个星星看成 左下点为x y 右上点为x+w-1 y+h-1 的矩形. 然后求出最大覆盖的和. #include <cstdio> ...

  10. POJ 2482 Stars in Your Window(线段树+扫描线)

    题目链接 非常不容易的一道题,把每个点向右上构造一个矩形,将问题转化为重合矩形那个亮度最大,注意LL,注意排序. #include <cstdio> #include <cstrin ...

随机推荐

  1. 香农的伟大论文《A Symbolic Analysis of Relay and Switching Circuits》

    香农在1938年发表的伟大论文A Symbolic Analysis of Relay and Switching Circuits(<对继电器和开关电路中的符号分析>)将开关.继电器.二 ...

  2. 页码0~N ,其中0,1....9都出现了几次

    /* 这道题目可以暴力解答:对1~n的每个数进行从低位到高位分析 一旦这个数字num出现,a[num]++即可 第二种方法: 由0,1,...9组成的所有n位数,从n个0到n个9共10^n个数,0,1 ...

  3. QQ联合登录(基于Oauth2.0协议)

    1. 获取授权码Authorization Code https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id= ...

  4. Django-04-路由系统

    1. 概述 URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL模式以及 2. path转换器 在django2.0 以上的版本中,默认使用的是path转换器,我们首先以此 ...

  5. count_if 功能模板

    count_if 功能模板 template <class InputIterator, class UnaryPredicate> typename iterator_traits< ...

  6. 收藏单词TOEFL备份托福英语

    TOEFL托福词汇串讲(文本) alchemy(chem-化学)n. 炼金术 chemistry 化学 alder 赤杨树 联想:older 老人坐在赤杨树下 sloth 树懒 algae n.海藻 ...

  7. python_进程与线程的补充

    进程与线程的标识 知识点一:进程id 与 线程ident import time import multiprocessing import threading time.sleep(10) prin ...

  8. Ambari深入学习(II)-实现细节

    在第一节中,我们简单讲了一下Ambari的系统架构.我们这一节主要分析Ambari的源代码,总览Ambari的具体实现方式及其工作细节. 一.Ambari-Server启动 Ambari-Server ...

  9. MVC中根据后台绝对路径读取图片并显示在IMG中

    数据库存取图片并在MVC3中显示在View中 根据路径读取图片: byte[] img = System.IO.File.ReadAllBytes(@"d:\xxxx.jpg"); ...

  10. Kubernetes Storage Persistent Volumes

    链接:https://kubernetes.io/docs/concepts/storage/persistent-volumes/ 支持的参数,比如mountOptions在这里可以找到 删除正在被 ...