(中等) 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> ...
随机推荐
- oracle中的turnc,round,floor,ceil,coalesce函数
这四个函数有点类似java中的函数,首先是 trunc(number,[decimals]) 这个函数类似截取函数 number:表示你要输入的数 decimals(小数): 表示你要截取的位数[正数 ...
- 关于tag,viewWithTag
iOS SDK内置了一套搜寻机制,可通过tag来查找子视图. **苹果公司很少给子视图设置tag.笔者所知范围的唯一例外出现在UIAlertView中,该类会给按钮分别设置值为1.2的标签 viewW ...
- struts2中的值栈对象ValueStack
ValueStack, 即值栈对象. 值栈对象: 是整个struts数据存储的核心,或者叫中转站. 用户每次访问struts的action,都会创建一个Action对象.值栈对象.ActionCont ...
- Template - Strategy
模板模式是一种基于继承的松耦合模式,其设计思路为,abstract类提供一组接口但不实现,不同concrete类继承同一接口并完成不同功能.如下图所示: 模板模式实现较为简单,TemplateMeth ...
- 自动打开notepad 并写入数据
import java.awt.AWTException; import java.awt.Robot; import java.awt.event.KeyEvent; import java.io. ...
- Swift 与 JSON 数据
转载自: http://www.cnblogs.com/theswiftworld/p/4660177.html 我们大家平时在开发 App 的时候,相信接触最多的就是 JSON 数据了.只要你的 A ...
- 使用命令行编译as文件成swf
设置环境变量到flex sdk的目录下.如:D:\Program Files\Adobe Flash Builder 4.5\sdks\flex_sdk_4.6\bin 找到flex-config.x ...
- IDL 遍历 XML文档示例
IDL解析XML文档同样也有2种方法:DOM和SAX方式:两种方法在IDL自带的帮助里面有详细介绍,可以去查看. IDL 源码PRO sample_recurse, oNode, indent COM ...
- Android Stduio的使用(七)--Structure窗口
1.本篇博文介绍Android查看.Java文件中所有属性和类方法的工具:Structure窗口 2.我们知道Eclipse的OutLine窗口可以查看.java文件所有的属性和方法. 2.Andro ...
- WebClient 访问间歇性返回403解决方案
说明:前段时间做的一个项目莫名的返回403的错误,这种情况也多大是程序员最不喜欢的了,没办法先来分析一下错误信息.之前的代码如下: WebClient webclient = new WebClien ...