(中等) POJ 2482 Stars in Your Window,静态二叉树。
// ━━━━━━神兽出没━━━━━━
// ┏┓ ┏┓
// ┏┛┻━━━━━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ████━████ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃
// ┃ ┃
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━━━━━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy
// Created Time : 2015年07月16日 星期四 16时33分23秒
// File Name : 2482_1.cpp // 注意:建的不是完全二叉树,所以空间要开大,然后就是注意lc和rc的越界问题(不知如何判,所以直接初始化为0)。 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int MaxN=; #define lc (po<<1)
#define rc ((po<<1)|1) struct DE
{
int a,b,c; bool operator < (const DE &b) const
{
return c<b.c;
}
}de[MaxN]; int decou=; struct BIT
{
int N;
long long key[MaxN],val[MaxN];
long long *numP; long long SUM[MaxN],MAXN[MaxN]; void _build(int L,int R,int po)
{
if(L>R)
return; de[decou].a=L;
de[decou].b=R;
de[decou].c=po;
++decou; int M=(L+R+)>>; _build(L,M-,lc); key[po]=numP[M];
val[po]=;
SUM[po]=MAXN[po]=; _build(M+,R,rc);
} void build(long long *num,int cou)
{
N=cou;
numP=num;
memset(SUM,,sizeof(SUM));
memset(MAXN,,sizeof(MAXN));
_build(,N,);
} void pushUP(int po)
{
/* long long Lnum,Rnum,Rmaxn,Lmaxn; if(lc>N)
Lnum=Lmaxn=0;
else
{
Lnum=SUM[lc];
Lmaxn=MAXN[lc];
} if(rc>N)
Rnum=Rmaxn=0;
else
{
Rnum=SUM[rc];
Rmaxn=MAXN[rc];
} SUM[po]=Lnum+Rnum+val[po];
MAXN[po]=max(Lmaxn,max(Lnum+val[po]+Rmaxn,Lnum+val[po]));*/ SUM[po]=SUM[lc]+SUM[rc]+val[po];
MAXN[po]=max(MAXN[lc],SUM[lc]+val[po]+max(0LL,MAXN[rc]));
} void _add(int po,long long k,long long num)
{
// if(po>N)
// return; if(k==key[po])
val[po]+=num;
else if(k<key[po])
_add(lc,k,num);
else
_add(rc,k,num); pushUP(po);
} void add(long long k,long long num)
{
_add(,k,num);
} long long query()
{
return MAXN[];
} void display()
{
for(int i=;i<=N;++i)
cout<<key[i]<<' '<<val[i]<<' '<<SUM[i]<<' '<<MAXN[i]<<endl;
cout<<endl;
}
}; BIT tree; struct Point
{
long long x,y,val; bool operator < (const Point &b) const
{
if(x==b.x)
return y<b.y; return x<b.x;
}
}; Point P[MaxN];
int N;
long long W,H;
int cou;
long long num[MaxN];
long long ans; long long getans()
{
if(W== || H==)
return ; int Lp,Rp; Lp=Rp=; for(int i=;i<=N;++i)
{
while(Lp<=N && P[Lp].x<P[i].x)
{
tree.add(P[Lp].y,-P[Lp].val);
tree.add(P[Lp].y+H,P[Lp].val);
++Lp;
} while(Rp<=N && P[Rp].x<P[i].x+W)
{
tree.add(P[Rp].y,P[Rp].val);
tree.add(P[Rp].y+H,-P[Rp].val);
++Rp;
} ans=max(ans,tree.query());
} return ans;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); while(~scanf("%d %lld %lld",&N,&W,&H))
{
ans=;
cou=; for(int i=;i<=N;++i)
{
scanf("%lld %lld %lld",&P[i].x,&P[i].y,&P[i].val);
num[++cou]=P[i].y;
num[++cou]=P[i].y+H;
} sort(P+,P+N+);
sort(num+,num+cou+);
cou=unique(num+,num+cou+)-num-; tree.build(num,cou); printf("%lld\n",getans());
} return ;
}
(中等) POJ 2482 Stars in Your Window,静态二叉树。的更多相关文章
- poj 2482 Stars in Your Window(扫描线)
id=2482" target="_blank" style="">题目链接:poj 2482 Stars in Your Window 题目大 ...
- POJ 2482 Stars in Your Window(线段树)
POJ 2482 Stars in Your Window 题目链接 题意:给定一些星星,每一个星星都有一个亮度.如今要用w * h的矩形去框星星,问最大能框的亮度是多少 思路:转化为扫描线的问题,每 ...
- 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 线段树扫描线
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 (线段树:区间更新)
题目链接:http://poj.org/problem?id=2482 读完题干不免有些心酸(
- POJ 2482 Stars in Your Window(扫描线+线段树)
[题目链接] http://poj.org/problem?id=2482 [题目大意] 给出一些点的二维坐标和权值,求用一个长H,宽W的矩形能框住的最大权值之和, 在矩形边缘的点不计算在内 [题解] ...
- 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 ...
- POJ 2482 Stars in Your Window
线段树+离散化+扫描线 AC之后,又认真读了一遍题目,好文章. #include<cstdio> #include<map> #include<algorithm> ...
随机推荐
- WinForm 子窗体在父窗体范围内移动,不能出父窗体 摘自于网络
详细解释:1, 主窗体Form1属性IsMdiContainer设为True,并添加ToolStrip控件, Toolstrip中添加一个按钮toolStripButton1. 2,添 ...
- servlet容器开发要点
v1 是一个http服务器. v2 是一个servlet容器, 可以提供servlet的服务. => 动态load servlet字节码,并运行它( 按生命周期). servlet容器它来 ...
- sqlserver内存释放
由于Sql Server对于系统内存的管理策略是有多少占多少,除非系统内存不够用了(大约到剩余内存为4M左右), Sql Server才会释放一点点内存.所以很多时候,我们会发现运行Sql Serv ...
- java transient修饰符
1)一旦变量被transient修饰,变量将不再是对象持久化的一部分,该变量内容在序列化后无法获得访问. 2)transient关键字只能修饰变量,而不能修饰方法和类.注意,本地变量是不能被trans ...
- codeforces 689B Mike and Shortcuts 最短路
题目大意:给出n个点,两点间的常规路为双向路,路长为两点之间的差的绝对值,第二行为捷径,捷径为单向路(第i个点到ai点),距离为1.问1到各个点之间的最短距离. 题目思路:SPFA求最短路 #incl ...
- 转:HTML错误编号大全
HTML错误编号大全 状态行包含HTTP版本.状态代码.与状态代码对应的简短说明信息.在大多数情况下,除了Content-Type之外的所有应答头都是可选的.但Content-Type是必需的,它描述 ...
- Hibernate 乐观锁(Optimistic Locking)
1.hibernate基于数据版本(Version)记录机制实现.为数据增加一个版本标识,一般是通过为数据库表增加一个"version"字段来实现. 读取出数据时,将此版本号一同读 ...
- MVC 使用Jquery的$.post传递参数
MVC中,如果要使用 $.post 给 COntroller 传递参数,需要类实现 属性 get set,这样才行
- dfs和bfs的简单总结
首先是dfs,又名深度优先搜索.看名字就知道,它的核心思想就是一直搜索,先在一条路上面一路撸到底,如果到底没有办法前进了,那么判断是否到达终点,如果没有到达,那么就回溯到之前的点再撸. dfs的要点: ...
- android:分享 一个很强大的LOG开关---Log.isLoggable
标签:android分享 一个很强大的log开 1.API亮点: 此API可以实现不更换APK,在出问题的手机上就直接能抓到有效log,能提升不少工作效率. 2.API介绍 最近在解决短信问题时,看到 ...