poj 2482 Stars in Your Window (线段树扫描线)
题目大意:
求一个窗体覆盖最多的星星的权值。
思路分析:
每个星星看成
左下点为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 (线段树扫描线)的更多相关文章
- 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 ...
- POJ 2482 Stars in Your Window(线段树+扫描线)
题目链接 非常不容易的一道题,把每个点向右上构造一个矩形,将问题转化为重合矩形那个亮度最大,注意LL,注意排序. #include <cstdio> #include <cstrin ...
- POJ 2482 Stars in Your Window 线段树
如果按一般的思路来想,去求窗户能框住的星星,就很难想出来. 如果换一个思路,找出每颗星星能被哪些窗户框住,这题就变得非常简单了. 不妨以每个窗户的中心代表每个窗户,那么每颗星星所对应的窗户的范围即以其 ...
- POJ 2482 Stars in Your Window (线段树区间合并+扫描线)
这题开始一直被矩形框束缚了,想法一直都是枚举线,但是这样枚举都需要O(n^2)...但是看了别人的思路,感觉这题思想真心很好(PS:开头好浪漫的描述啊,可惜并没有什么用) 题意就是在平面上给你一些星 ...
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- poj 2482 Stars in Your Window + 51Nod1208(扫描线+离散化+线段树)
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13196 Accepted: ...
- POJ 2482 Stars in Your Window(线段树)
POJ 2482 Stars in Your Window 题目链接 题意:给定一些星星,每一个星星都有一个亮度.如今要用w * h的矩形去框星星,问最大能框的亮度是多少 思路:转化为扫描线的问题,每 ...
- poj 2482 Stars in Your Window(扫描线)
id=2482" target="_blank" style="">题目链接:poj 2482 Stars in Your Window 题目大 ...
- POJ 2482 Stars in Your Window 离散化+扫描法 线段树应用
遇见poj上最浪漫的题目..题目里图片以上几百词为一篇模板级英文情书.这情感和细腻的文笔深深地打动了我..不会写情书的童鞋速度进来学习.传送门 题意:坐标系内有n个星星,每个星星都有一个亮度c (1& ...
- POJ 2482 Stars in Your Window (线段树+扫描线+区间最值,思路太妙了)
该题和 黑书 P102 采矿 类似 参考链接:http://blog.csdn.net/shiqi_614/article/details/7819232http://blog.csdn.net/ts ...
随机推荐
- Windows 重装系统-用户转移User和Program Files 文件夹
原文地址:https://blog.csdn.net/sinat_38799924/article/details/74059037 重装系统时为了让系统数据保持可用我们需要做一些备份处理.比如用户数 ...
- 使用SQL Server发送邮件时遇到的诡异事件
最近公司要实现一个邮件群发的功能,因此设计时就考虑用SQL Server的邮件发送功能直接推送邮件算了. 可是在实现的过程中,邮件内容中有一个表格的内容要展现,于是就编排了一个表格来实现. 具体实现如 ...
- AndroidStudio 编译异常java.lang.OutOfMemoryError: GC overhead limit exceeded
在build.gradle中的android{}添加如下脚本就可以顺利编译了 dexOptions { incremental true javaMaxHeapSize “4g” }
- Oracle 12C -- 使用local PDB克隆新的PDB
1.将用于克隆的PDB至于只读状态:startup open read only SQL> select con_id,name,open_mode from v$pdbs; CON_ID NA ...
- df -h和du -sh显示结果不一样的原因及解决
一.背景:一台2T硬盘的mysql服务器,保存电话的CDR信息.按照历史数据的水平,一个月能生成20+GB的文件.然而短短的半年时间,满了?! 登录服务器看谁占了这么大的空间?好吧,slow-quer ...
- VS Code 中文注释显示乱码
将设置中的"files.autoGuessEncoding"项的值改为true即可. 1.文件 2.首选项 3.设置 4.搜索 "files.autoGuessEncod ...
- 微信小程序JS导出和导入
1. 导出 1.1 方法和变量导出(写在被导出方法和变量的js文件) module.exports = { variable: value, method : methodName } 1.2 cla ...
- 持续集成(1)gitlab的安装
操作系统:centos 6.5 关闭selinux # 修改/etc/selinux/config 文件 将SELINUX=enforcing改为SELINUX=disabled ,然后重启电脑 # ...
- scala中json与对象的转换
遇到的问题 因为要把spark从es读出来的json数据转换为对象,开始想用case class定义类型,通过fastjson做转换.如下 case class Book (author: Strin ...
- Android Studio 1.1.0 “关联源码” 或者“导入源码” ,又或者插件包
其实这博文是废话!为什么呢? 1.如果自己的SDK没有更新相应当前操作版本的source的话,相应的v4,v7等等的源码都不会自动导入的. 其实Android Studio自身就已经会去检测你当前SD ...