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 ...
随机推荐
- centos6.4安装GitLab
参考文章: http://www.pickysysadmin.ca/2013/03/25/how-to-install-gitlab-5-0-on-centos-6/ yum安装redis的方法: h ...
- 解决虚拟机vmware虚拟机安装64位系统“此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态”的问题
前言 虚拟机使用的是VMware Workstation,并且首次在虚拟机体验64 位系统.在新建好虚拟机,运行时候就出现了VMware Workstation 的提醒:此主机支持 Intel VT- ...
- matlab入门笔记(七):数据文件I/O
- 来设置IE兼容模式
来设置IE兼容模式 文件兼容性用于定义让IE如何编译你的网页.此文件解释文件兼容性,如何指定你网站的文件兼容性模式以及如何判断一个网页该使用的文件模式. 前言 为了帮助确保你的网页在所有未来的IE版本 ...
- 使用mysqldump导入导出MySQL数据库
数据库的基本导入\导出的命令 是 mysqldump 和 source 在linux下直接用命令行操作就可以 在windows下 一般情况下有两种方法一个也是用命令行 另一个是用phpmyadmin ...
- Android Activity全面解析
Android Activity全面解析 首先,就从Android四大组件Activity开始. 1.Activity生命周期方法完全解析 activity_lifecycle.png 1).on ...
- Windows8.1远程桌面时提示凭据不工作的解决方案
本人两台电脑都是win8.1.首先确认以下三点: 1.密码没有错 2.用户连接没有达到上线(只有我一个人尝试连) 3.该用户已开启远程连接 此时还说凭据不工作的原因是域的问题,因为mstsc默认使用M ...
- CentOS 7.3 安装指南
摘要: 基于 Red Hat 企业版的源代码的最新版本的 CentOS 7 在今年的 12月发布了 CentOS Linux 7 (1611),包含了许多 bug 修复.新的包更新,比如 Samba. ...
- Nginx+tomcat组合实现高并发场景的动静分离和负载均衡方案
简介 Java服务大多是跑在tomcat里,但是众所周知tomcat的并发性能没有优势(tomcat8及以上的版本可能有所改善),所以为了更好的适应高并发的应用场景,我们可以使用tomcat+ngin ...
- pyqt5开发环境安装
1.下载所需软件. Anaconda下载地址:https://repo.continuum.io/archive/ PyQt5下载地址:https://sourceforge.net/projects ...