题意:二维平面上给你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. Ubuntu16.04环境下的硬盘挂载

    需求:在Ubuntu16.04系统下,挂载一个新的硬盘 第一步:查看目前已经存在的分区的状态 命令:df -l 如上图所示,并未看到要挂载的硬盘(sda)的状态. 第二步:查看计算机硬盘的状态(包括格 ...

  2. React 的高级用法(Children、Component、createElement、cloneElement)

    React.Children props.children 代表了所有的子节点. React.Children 用于处理 props.children 的 提供了几个方法 ( map ,foreach ...

  3. 使用SSM搭建一个简单的crud项目

    使用SSM完成增删查改 前端使用到的技术:ajax,json,bootstrap等 完整项目地址:点这里GitHub 项目地址,可以在线访问 这一章节主要搭建SSM的环境. SpringMVC Spr ...

  4. python基础教程_查询价格

    少儿编程和数学是有这一定联系的,若是将编程弄好了,数学成绩也就会有所提高,今天就为大家来介绍一下一个关于数学的相关编程,现在我们就来看看吧! 题目描述 编程实现以下功能:查询水果的单价.有4种水果,苹 ...

  5. 文件和异常的练习3——python编程从入门到实践

    10-10 常见单词:访问项目Gutenberg(http://gutenberg.org/),并找一些你想分析的图书.下载这些作品的文本文件或将浏览器中的原始文本复制到文本文件中. 可以使用coun ...

  6. 快速排序(Quick Sort)C语言

    已知数组 src 如下: [5, 3, 7, 6, 4, 1, 0, 2, 9, 10, 8] 快速排序1 在数组 src[low, high] 中,取 src[low] 作为 关键字(key) . ...

  7. Hive 系列(二)—— Linux 环境下 Hive 的安装部署

    一.安装Hive 1.1 下载并解压 下载所需版本的 Hive,这里我下载版本为 cdh5.15.2.下载地址:http://archive.cloudera.com/cdh5/cdh/5/ # 下载 ...

  8. 为 WPF 程序添加 Windows 跳转列表的支持

    原文:为 WPF 程序添加 Windows 跳转列表的支持 Windows 跳转列表是自 Windows 7 时代就带来的功能,这一功能是跟随 Windows 7 的任务栏而发布的.当时应用程序要想用 ...

  9. "Sed" 高级实用功能汇总

    sed命令有两个空间,一个叫pattern space,一个叫hold space.这两个空间能够证明人类的脑瓜容量是非常小的,需要经过大量的训练和烧脑的理解,才能适应一些非常简单的操作. 不信看下面 ...

  10. pandas-11 TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely错误解决方法

    pandas-11 TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be sa ...