POJ 2482 Stars in Your Window
线段树+离散化+扫描线
AC之后,又认真读了一遍题目,好文章。
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std; const int maxn=+;
int n;
long long W,H;
long long x[maxn],y[maxn],v[maxn];
struct seg
{
long long X;
long long Y1,Y2;
long long val;
}s[*maxn];
struct SegTree
{
long long MAX;
long long add;
}segTree[*maxn]; map<long long,int>m;
long long M[maxn];
int k; bool cmp(const seg&a,const seg&b)
{
if(a.X==b.X) return a.val>b.val;
return a.X<b.X;
} void pushUp(int rt)
{
segTree[rt].MAX=max(segTree[*rt].MAX,segTree[*rt+].MAX);
} void pushDown(int rt)
{
if(segTree[rt].add)
{
segTree[*rt].add+=segTree[rt].add;
segTree[*rt+].add+=segTree[rt].add;
segTree[*rt].MAX+=segTree[rt].add;
segTree[*rt+].MAX+=segTree[rt].add;
segTree[rt].add=;
}
} void build(int l,int r,int rt)
{
segTree[rt].add=;
segTree[rt].MAX=;
if(l==r) return; int m=(l+r)/;
build(l,m,*rt);
build(m+,r,*rt+);
} void update(long long val,int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
segTree[rt].add+=val;
segTree[rt].MAX+=val;
return;
} pushDown(rt);
int m=(l+r)/;
if(L<=m) update(val,L,R,l,m,*rt);
if(R>m) update(val,L,R,m+,r,*rt+);
pushUp(rt);
} void lsh()
{
m.clear();
k=;
for(int i=;i<=n;i++)
{
if(m[y[i]]==)
{
m[y[i]]=;
M[k++]=y[i];
}
if(m[y[i]+H-]==)
{
m[y[i]+H-]=;
M[k++]=y[i]+H-;
}
}
sort(M,M+k);
//m.clear(); 这个地方比较奇葩。清空了会TLE。。。。
for(int i=;i<k;i++) m[M[i]]=i+;
} int main()
{
//freopen("F:\\in.txt","r",stdin);
while(~scanf("%d%lld%lld",&n,&W,&H))
{
for(int i=;i<=n;i++) scanf("%lld%lld%lld",&x[i],&y[i],&v[i]);
lsh();
int tot=;
for(int i=;i<=n;i++)
{
s[tot].X=x[i];
s[tot].Y1=m[y[i]];
s[tot].Y2=m[y[i]+H-];
s[tot].val=v[i];
tot++; s[tot].X=x[i]+W-;
s[tot].Y1=m[y[i]];
s[tot].Y2=m[y[i]+H-];
s[tot].val=-v[i];
tot++;
} sort(s,s+tot,cmp); build(,k,); long long max_val=; for(int i=;i<tot;i++)
{
update(s[i].val,s[i].Y1,s[i].Y2,,k,);
max_val=max(segTree[].MAX,max_val);
}
printf("%lld\n",max_val);
}
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,静态二叉树。
Description Here comes the problem: Assume the sky is a flat plane. All the stars lie on it with a l ...
- 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 ...
随机推荐
- perl命令+关键字
来源: http://www.cnblogs.com/itech/archive/2012/11/01/2749666.html http://www.garybeene.com/vb/tut-per ...
- perl的Getopt::Long和pod::usage ?
来源: http://www.cnblogs.com/itech/archive/2012/08/07/2627267.html 代码: 需要显式地定义变量且初始化.例如optionX. 如果没有定义 ...
- spring xsd
http://ljhzzyx.blog.163.com/blog/static/3838031220132239471608/ spring配置文件报找不到xsd文件错误 2013-03-23 10: ...
- hash随笔
hash属性是一个可读可写的字符串,是url的锚部分(从#开始).多用于单页面应用中,使其包含多个页面. 定位:通过id来定位 eg: <div id= "part1"> ...
- 【经典dp】 poj 3671
开一个dp[30010][3]的数组 其中dp[i][j]表示把第i个数改成j最少要花多少次 那么状态转移方程就列出来了: 令a=1 j!=a[i] 0 j==a[i] 那么dp[i][1]=dp[i ...
- popoverController(iPad)
一.设置尺寸 提示:不建议,像下面这样吧popover的宽度和高度写死. 1 //1.新建一个内容控制器 2 YYMenuViewController *menuVc=[[YYMenuViewCont ...
- 关于:hover的一点小问题
今天又用到了:hover这个伪类选择器,一个小问题搞了我好久,就是关于:hover选择的问题, 先看下css代码 .box:hover span { height: 150px; } 接下来是HTML ...
- maven学习笔记 1
1 概述 1.1 Maven是什么 1.2 为什么要用Maven 2 怎么用Maven 2.1 Maven仓库 2.2 Maven安装 2.3 Eclipse插件 2.4 Maven常用命 ...
- Chapter 1 First Sight——19
"I'm headed toward building four, I could show you the way…" Definitely over-helpful. &quo ...
- PAT1003
As an emergency rescue team leader of a city, you are given a special map of your country. 作为一个城市的紧急 ...