题目大意:

求一个窗体覆盖最多的星星的权值。

思路分析:

每个星星看成

左下点为x y

右上点为x+w-1 y+h-1 的矩形。

然后求出最大覆盖的和。

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define lson num<<1,s,mid
#define rson num<<1|1,mid+1,e
#define maxn 10005
using namespace std;
typedef long long LL;
LL res[maxn<<4];
LL sum[maxn<<4];
LL x[maxn<<4]; struct node
{
LL s,e,h,type;
bool operator < (const node &cmp)const
{
if(h==cmp.h)return type>cmp.type;
return h<cmp.h;
}
}scline[maxn<<1]; void pushup(int num)
{
sum[num]=max(sum[num<<1],sum[num<<1|1]);
}
void pushdown(int num)
{
if(res[num])
{
sum[num<<1]+=res[num];
sum[num<<1|1]+=res[num];
res[num<<1]+=res[num];
res[num<<1|1]+=res[num];
res[num]=0;
}
}
void build(int num,int s,int e)
{
res[num]=0;
sum[num]=0;
if(s==e)return;
int mid=(s+e)>>1;
build(lson);
build(rson);
}
void update(int num,int s,int e,int l,int r,LL val)
{
if(l<=s && r>=e)
{
res[num]+=val;
sum[num]+=val;
return;
}
int mid=(s+e)>>1;
pushdown(num);
if(l<=mid)update(lson,l,r,val);
if(r>mid)update(rson,l,r,val);
pushup(num);
}
int main()
{
LL n,w,h;
while(cin>>n>>w>>h)
{
for(int i=1;i<=n;i++)
{
LL ts,te,tt;
cin>>ts>>te>>tt;
scline[i*2-1].s=ts,scline[i*2-1].e=ts+w-1,scline[i*2-1].h=te,scline[i*2-1].type=tt;
scline[i*2].s=ts,scline[i*2].e=ts+w-1,scline[i*2].h=te+h-1,scline[i*2].type=-tt;
x[i*2-1]=ts,x[i*2]=ts+w-1;
}
sort(scline+1,scline+1+n*2);
sort(x+1,x+1+n*2);
int m=unique(x+1,x+1+n*2)-x; build(1,1,m);
LL ans=0;
for(int i=1;i<=n*2;i++)
{
int l=lower_bound(x+1,x+m,scline[i].s)-x;
int r=lower_bound(x+1,x+m,scline[i].e)-x;
update(1,1,m,l,r,scline[i].type);
ans=max(ans,sum[1]);
}
cout<<ans<<endl;
}
return 0;
}
/*
2 1 5
0 0 100
0 4 101
*/

poj 2482 Stars in Your Window (线段树扫描线)的更多相关文章

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

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

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

  3. POJ 2482 Stars in Your Window 线段树

    如果按一般的思路来想,去求窗户能框住的星星,就很难想出来. 如果换一个思路,找出每颗星星能被哪些窗户框住,这题就变得非常简单了. 不妨以每个窗户的中心代表每个窗户,那么每颗星星所对应的窗户的范围即以其 ...

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

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

  5. 【POJ-2482】Stars in your window 线段树 + 扫描线

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

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

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

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

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

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

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

  9. POJ 2482 Stars in Your Window 离散化+扫描法 线段树应用

    遇见poj上最浪漫的题目..题目里图片以上几百词为一篇模板级英文情书.这情感和细腻的文笔深深地打动了我..不会写情书的童鞋速度进来学习.传送门 题意:坐标系内有n个星星,每个星星都有一个亮度c (1& ...

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

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

随机推荐

  1. Docker K8s基本概念入门

    原文地址:https://blog.csdn.net/TM6zNf87MDG7Bo/article/details/79621510 k8s是一个编排容器的工具,其实也是管理应用的全生命周期的一个工具 ...

  2. PopUpWindow使用详解(二)——进阶及答疑

      相关文章:1.<PopUpWindow使用详解(一)——基本使用>2.<PopUpWindow使用详解(二)——进阶及答疑> 上篇为大家基本讲述了有关PopupWindow ...

  3. 豆瓣上9分以上的IT书籍-编程语言篇

    我当要学习某些技术时,第一时间就是去找相关的书籍.而豆瓣读书是我主要的参考依据,主要是它的评分基本比较靠谱,对于技术书籍,一般来说评分在8分以上就是不错的书籍了,而达到9分就可以列入"必读& ...

  4. FreeSWITCH协议参数之自定义sip header

    一.主动发送 1. 加入sip_h_前缀 这样FreeSWITCH就能自动加上后面的扩展头. 2. 示例 <action application="set" data=&qu ...

  5. [转]JVM参数设置、分析

    不管是YGC还是Full GC,GC过程中都会对导致程序运行中中断,正确的选择不同的GC策略,调整JVM.GC的参数,可以极大的减少由于GC工作,而导致的程序运行中断方面的问题,进而适当的提高Java ...

  6. [转] Spring4.3.x 浅析xml配置的解析过程(6)——解析context命名空间之property-placeholder和property-override标签

    在上一篇解析自定义命名空间的标签中,我们已经知道解析自定义命名空间的标签需要用到NamespaceHandler接口的实现类,并且知道spring是如何获取命名空间对应的命名空间处理器对象的.因此我们 ...

  7. Java 8 flatMap example

    Java 8 flatMap example In Java 8, Stream can hold different data types, for examples: Stream<Stri ...

  8. EndNote 输出样式模板(根据国家标准制订)

    EndNote 输出样式模板(根据国家标准制定)   EndNote 相当于一个数据库,将添加/导入的文献存档.需要引用文献的时候就从中选择一个插入到文档中,EndNote 会自动给你编号.在文档末尾 ...

  9. 解决iPad/iPhone下手机号码会自动被加上a标签的问题

    解决办法: 在页面顶部<head></head>中增加: <meta name="format-detection" content="te ...

  10. kafka 监控(eagle)

    topic:创建时topic名称 partition:分区编号 offset:表示该parition已经消费了多少条message logSize:表示该partition已经写了多少条message ...