题目大意:

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

思路分析:

每个星星看成

左下点为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. [AaronYang]C#人爱学不学[1]

    当前编写时间:2014年12月24日21:11:14   编写人:杨洋(Aaronyang) 新文章:[AaronYang]C#人爱学不学[1] 声明:->可以理解为 联想到,或者关联的意思. ...

  2. Java Nashorn--Part 4

    Nashorn 和 javax.script 包 Nashorn 并不是第一个在 Java 平台上运行的脚本语言.在Java 6 就提供了 javax.script java 包,它为脚本语言引擎提供 ...

  3. unity, unity默认的Arial字体在编译出的h5版本中不显示

    unity默认的Arial字体在编译出的h5版本中不显示.改用自己的字体可显示.

  4. UI控件篇——UIPageControl及其自定义

    UIPageControl类提供一行点来指示当前显示的是多页面视图的哪一页.当然,由于UIPageControl类可视样式的点击不太好操作,所以最好是确保再添加了可选择的导航选项,以便让页面控件看起来 ...

  5. win764bit系统plsqldeveloper11连接oracle11g64bit配置方法

    win764bit系统plsqldeveloper11连接oracle11g64bit配置方法: 原因:plsqldeveloper都是32位的没有64位的程序 准备工作: 1,先要下载instant ...

  6. Python 构建方便的函数调用

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-14 @author: guaguastd @name: c ...

  7. Atitit 软件体系的进化,是否需要一个处理中心

    Atitit 软件体系的进化,是否需要一个处理中心 1.1. 进化树上是没有主干的..1 1.2. ,软件进化的行为1::主要就是给新的应用编写新的程序.1 1.3. ,软件进化的行为2::软件的维护 ...

  8. 【Android】1.1 开发环境安装和配置

    分类:C#.Android.VS2015: 创建日期:2016-01-20 2016-08-03说明:此版本已过时,最新版本见本博客置顶的内容. 一.安装JDK.SDK.NDK 无论是用C#和VS20 ...

  9. Vue2 原理解析

    现代主流框架均使用一种数据=>视图的方式,隐藏了繁琐的dom操作,采用了声明式编程(Declarative Programming)替代了过去的类jquery的命令式编程(Imperative ...

  10. Gartner:2018人工智能技术成熟度曲线

    https://www.secrss.com/articles/4392 人工智能被广为关注,但是一些想法恐难达到预期.本成熟度曲线将追踪AI基本趋势和未来创新,以确定人工智能技术发展的范围.状态.价 ...