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 ...
随机推荐
- 知识点:Oracle+表连接方式(内连接-外连接-自连接)+详解 来自百度文库
Oracle 表之间的连接分为三种: 1. 内连接(自然连接) 2. 外连接 (1)左外连接 (左边的表不加限制) (2)右外连接(右边的表不加限制) (3)全外连接(左右 ...
- PySpark 行列转换
Spark实现行列转换pivot和unpivot 背景 做过数据清洗ETL工作的都知道,行列转换是一个常见的数据整理需求. 首先明确一下啥叫行列转换,因为这个叫法也不是很统一,有的地方叫转置,有的地方 ...
- laravel用redis保存session遇到的坑,没报错,但redis-cli就是查不到
laravel用redis保存session遇到的坑, 配置redis存储session流程是这样的 在.evn文件中把session驱动和连接改为了redis的 如下: SESSION_DRIVER ...
- WPF中动态改变控件显示位置
转自 http://blog.csdn.net/lassewang/article/details/6928897 测试环境: Windows XP/Windows 7 开发环境: Microsoft ...
- php分享二十八:mysql运行中的问题排查
一:杀掉mysql连接的方法: kill thread_id: 杀掉当前进程,断开连接 kill query thread_id: 只杀掉某连接当前的SQL,而不断开连接. 批量杀死MySQL连接的 ...
- JS 在 IE9 中出现奇怪的错误(参数是必选项 argument not optional)
最近发现之前运行正常的网站,在 IE9 下会报这个错误.网上查了一下,发现是跟我的方法名字有关... 我起了一个叫做 addFilter 名字的方法,但是很不巧,IE9 里也有一个这个名字的方法,所以 ...
- [LeetCode] Basic Calculator & Basic Calculator II
Basic Calculator Implement a basic calculator to evaluate a simple expression string. The expression ...
- 程序包org.junit不存在和编码GBK的不可映射字符问题解决
maven项目在打包编译时提示: 解决办法: 将pom中junit依赖中的scope给注释掉 <dependency> <groupId>junit</groupId&g ...
- 【Unity】11.4 车轮碰撞体(Wheel Collider)
分类:Unity.C#.VS2015 创建日期:2016-05-02 一.简介 车轮碰撞体 (Wheel Collider)专门用于创建汽车或其他移动交通工具. 车轮碰撞体是一种针对地面车辆的特殊碰撞 ...
- create-react-app 使用详解
快速开始 npm install -g create-react-app create-react-app my-app cd my-app/ npm start 通过http://localhost ...