【题目链接】 http://poj.org/problem?id=2482

【题目大意】

  给出一些点的二维坐标和权值,求用一个长H,宽W的矩形能框住的最大权值之和,
  在矩形边缘的点不计算在内

【题解】

  我们计算能扫到这个点的区间范围,将其拆分为两条平行于y轴的左闭右开的直线,
  为方便边界处理,我们将坐标扩大两倍,之后我们按照x轴对这些线段进行扫描
  统计出现的最大值即可。

【代码】

#include <cstdio>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long LL;
const int N=10010;
LL xs[N],ys[N],X[N<<1],Y[N<<1];
int cs[N],tag[N<<3],T[N<<3];
pair<pair<int,int>,pair<int,int> >event[N<<1];
void update(int L,int R,int v,int x,int l,int r){
if(L<=l&&r<=R){T[x]+=v;tag[x]+=v;return;}
int mid=(l+r)>>1;
if(L<=mid)update(L,R,v,x<<1,l,mid);
if(mid<R)update(L,R,v,x<<1|1,mid+1,r);
T[x]=max(T[x<<1],T[x<<1|1])+tag[x];
}
int n,W,H;
void solve(){
for(int i=0;i<n;i++){
scanf("%lld%lld%d",xs+i,ys+i,cs+i);
xs[i]<<=1; ys[i]<<=1;
}
for(int i=0;i<n;i++){
X[i<<1]=xs[i]-W; X[i<<1|1]=xs[i]+W;
Y[i<<1]=ys[i]-H; Y[i<<1|1]=ys[i]-1+H;
}sort(X,X+n*2);sort(Y,Y+n*2);
for(int i=0;i<n;i++){
event[i<<1]=make_pair(make_pair(lower_bound(X,X+n*2,xs[i]-W)-X,cs[i]),make_pair(lower_bound(Y,Y+n*2,ys[i]-H)-Y,lower_bound(Y,Y+n*2,ys[i]+H-1)-Y));
event[i<<1|1]=make_pair(make_pair(lower_bound(X,X+n*2,xs[i]+W)-X,-cs[i]),make_pair(lower_bound(Y,Y+n*2,ys[i]-H)-Y,lower_bound(Y,Y+n*2,ys[i]+H-1)-Y));
}sort(event,event+n*2);
int ans=0;
for(int i=0;i<n*2;i++){
update(event[i].second.first,event[i].second.second,event[i].first.second,1,0,n*2);
ans=max(ans,T[1]);
}printf("%d\n",ans);
}
int main(){
while(~scanf("%d%d%d",&n,&W,&H))solve();
return 0;
}

POJ 2482 Stars in Your Window(扫描线+线段树)的更多相关文章

  1. POJ 2482 Stars in Your Window(线段树)

    POJ 2482 Stars in Your Window 题目链接 题意:给定一些星星,每一个星星都有一个亮度.如今要用w * h的矩形去框星星,问最大能框的亮度是多少 思路:转化为扫描线的问题,每 ...

  2. POJ 2482 Stars in Your Window (线段树+扫描线+区间最值,思路太妙了)

    该题和 黑书 P102 采矿 类似 参考链接:http://blog.csdn.net/shiqi_614/article/details/7819232http://blog.csdn.net/ts ...

  3. poj 2482 Stars in Your Window (线段树扫描线)

    题目大意: 求一个窗体覆盖最多的星星的权值. 思路分析: 每个星星看成 左下点为x y 右上点为x+w-1 y+h-1 的矩形. 然后求出最大覆盖的和. #include <cstdio> ...

  4. poj 2482 Stars in Your Window (线段树:区间更新)

    题目链接:http://poj.org/problem?id=2482 读完题干不免有些心酸(

  5. poj 2482 Stars in Your Window(扫描线)

    id=2482" target="_blank" style="">题目链接:poj 2482 Stars in Your Window 题目大 ...

  6. 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)

    [POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

  7. poj 2482 Stars in Your Window + 51Nod1208(扫描线+离散化+线段树)

    Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13196   Accepted:  ...

  8. 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 ...

  9. POJ 2482 Stars in Your Window (线段树区间合并+扫描线)

    这题开始一直被矩形框束缚了,想法一直都是枚举线,但是这样枚举都需要O(n^2)...但是看了别人的思路,感觉这题思想真心很好(PS:开头好浪漫的描述啊,可惜并没有什么用)  题意就是在平面上给你一些星 ...

  10. POJ 2482 Stars in Your Window 离散化+扫描法 线段树应用

    遇见poj上最浪漫的题目..题目里图片以上几百词为一篇模板级英文情书.这情感和细腻的文笔深深地打动了我..不会写情书的童鞋速度进来学习.传送门 题意:坐标系内有n个星星,每个星星都有一个亮度c (1& ...

随机推荐

  1. 【BZOJ 4034】[HAOI2015]树上操作 差分+dfs序+树状数组

    我们只要看出来这道题 数组表示的含义就是 某个点到根节点路径权值和就行 那么我们可以把最终答案 看做 k*x+b x就是其深度 ,我们发现dfs序之后,修改一个点是差分一个区间,修改一个点的子树,可以 ...

  2. CSS样式权重的级联cascade的概念

    我们知道,firefox在众多浏览器中是对css 2高度兼容的一款浏览器,那是我能够编写一个中型b2b网站的时候(并不能说是我遇到过的难题)在禅意花园中看到的一个案例,说的是某个菜单在css中定义了以 ...

  3. How to reclaim space in InnoDB when innodb_file_per_table is ON

    When innodb_file_per_table is OFF and all data is going to be stored in ibdata files. If you drop so ...

  4. lesson 1

    1.当前只是开始接触,安装并开始熟悉Visual Studio 的操作界面及基本设置 2.学习了新建项目,简单的hello world,及对颜色的更改.

  5. POJ1182 食物链---(经典种类并查集)

    题目链接:http://poj.org/problem?id=1182   食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submission ...

  6. LeetCode 4 :Majority Element

    problem:Given an array of size n, find the majority element. The majority element is the element tha ...

  7. rtp包格式

    转载一篇帮助我了解h264 rtp的文档,地址http://www.cppblog.com/czanyou/archive/2009/12/25/67940.html 当packetization-m ...

  8. linux下命令源码

    一般来说,不同的命令可能隶属于不同的软件包,这样就没有一个地方会有所有命令的源代码.(命令的个数也会与你所安装的软件包有关)但是,一些常用的命令,例如basename cat chgrp chmod ...

  9. python 监控redis的进程与端口

    #!/usr/bin/python # -*- coding:utf-8 -*- import glob,psutil import json,os,datetime import collectio ...

  10. React.js入门

    React 入门实例教程   现在最热门的前端框架,毫无疑问是 React . 上周,基于 React 的 React Native 发布,结果一天之内,就获得了 5000 颗星,受瞩目程度可见一斑. ...