【题目链接】 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. pmap用法小计

    By francis_hao    Aug 4,2017   pmap-报告进程的内存映射.   概要 pmap [options] pid [...]   描述 pmap命令用来报告一个或多个进程的 ...

  2. ExtJS 4.1 TabPanel动态加载页面并执行脚本【转】

    ExtJS 4.1 TabPanel动态加载页面并执行脚本 按照官方示例,可以动态加载页面,可是脚本不执行,于是查SDK.google,发现scripts需要设置为true,于是设置该属性,整个代码如 ...

  3. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) B

    B. Little Artem and Grasshopper time limit per test 2 seconds memory limit per test 256 megabytes in ...

  4. 洛谷P1346 电车

    P1346 电车 236通过 757提交 题目提供者yeszy 标签图论福建省历届夏令营 难度普及/提高- 提交该题 讨论 题解 记录 最新讨论 解不好啊,快疯了!!哪位大… 求解:为何除了-1的点之 ...

  5. Optimize Prime Sieve

    /// A heavily optimized sieve #include <cstdio> #include <cstring> #include <algorith ...

  6. codefoeces 671 problem D

    D. Roads in Yusland standard output Mayor of Yusland just won the lottery and decided to spent money ...

  7. codeforces613B - Skills &&金中市队儿童节常数赛

    题目传送门 本随笔写的是第二题...... 这道题方法就是搞乱....因为n较mxa小 所以枚举达到最大上限的点 然后就乱搞 代码看看咯 #include<cstdio> #include ...

  8. 【CF1027D】Mouse Hunt(拓扑排序,环)

    题意:给定n个房间,有一只老鼠可能从其中的任意一个出现, 在第i个房间设置捕鼠夹的代价是a[i],若老鼠当前在i号房间则下一秒会移动到b[i]号, 问一定能抓住老鼠的最小的总代价 n<=2e5, ...

  9. 【CodeForces】841C. Leha and Function(Codeforces Round #429 (Div. 2))

    [题意]定义函数F(n,k)为1~n的集合中选择k个数字,其中最小数字的期望. 给定两个数字集A,B,A中任意数字>=B中任意数字,要求重组A使得对于i=1~n,sigma(F(Ai,Bi))最 ...

  10. 2017年上海金马五校程序设计竞赛:Problem G : One for You (博弈)

    Description Given a m × n chessboard, a stone is put on the top-left corner (1, 1). Kevin and Bob ta ...