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 ...
随机推荐
- 用For Each语句对Session.Contents树组进行遍历
<%@ LANGUAGE=VBScript codepage ="936" %> <% Option Explicit %> 您的sessionID号是:& ...
- sql server 数据库导出表里所有数据成insert 语句
有时候,我们想把数据库的某张表里的所有数据导入到另外一个数据库或另外一台计算机上的数据库,对于sql server有这样的一种方法 下面我以sql server 2008 R2,数据库是Northwi ...
- table详解
1.tr 元素定义表格行,th 元素定义表头,td 元素定义表格单元. tr内是th还是td可由自己定义,th,td可存在于任一行,th与td的区别在与th字体更粗 2.定义一个table默认有bor ...
- 转 Problem: AnyConnect was not able to establish a connection to the specified secu
不多说直接上问题,在点击连接时,也是能正常连接上输入密码,在输出用户名密码后 连接后,会出现: problem:anyconnect was net able to establish a conne ...
- Tourists
Tourists 时间限制: 5 Sec 内存限制: 64 MB 题目描述 In Tree City, there are n tourist attractions uniquely labele ...
- WebSocket学习笔记——无痛入门
WebSocket学习笔记——无痛入门 标签: websocket 2014-04-09 22:05 4987人阅读 评论(1) 收藏 举报 分类: 物联网学习笔记(37) 版权声明:本文为博主原 ...
- webservice接口调用存储过程返回失败
poka.cashman.timer.service.impl.PdaOperateServiceImpl - Method Name: cashBoxOutOrIn; cbInfo:JN002015 ...
- [转]View属性 之 paddingStart & paddingEnd
[CAUSE] 在写一个自定义View时, 直接复制了Android-Source的XML布局文件, 默认开发SDK版本是4.2.2(Level-API-17), 后因其他原因将SDK版本改为4.1. ...
- 多校 Cow Bowling
题目链接:http://acm.hust.edu.cn/vjudge/contest/124435#problem/I 密码:acm Sample Input Sample Output 分析: #i ...
- ubuntu11.10server 安装php-redis插件
1.下载php-redis插件 1 sudo wget https://github.com/nicolasff/phpredis/archive/master.zip 2.安装 1 2 3 4 5 ...