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

题目大意:平面上有N个星星。问一个W∗H的矩形最多能括进多少个星星。

解题思路:扫描线的变形。仅仅要以每一个点为左上角。建立矩形,这个矩形即为框框左下角放的位置能够括到该点,那么N个星星就有N个矩形,扫描线处理哪些位置覆盖次数最多。

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm> using namespace std; typedef long long ll;
const int maxn = 40000; #define lson(x) ((x)<<1)
#define rson(x) (((x)<<1)|1) int lc[maxn << 2], rc[maxn << 2];
ll v[maxn << 2], s[maxn << 2]; inline void pushup (int u) {
s[u] = max(s[lson(u)], s[rson(u)]) + v[u];
} inline void maintain (int u, int d) {
v[u] += d;
pushup(u);
} void build (int u, int l, int r) {
lc[u] = l;
rc[u] = r;
v[u] = s[u] = 0; if (l == r)
return; int mid = (l + r) / 2;
build(lson(u), l, mid);
build(rson(u), mid + 1, r);
pushup(u);
} void modify (int u, int l, int r, int d) {
if (l <= lc[u] && rc[u] <= r) {
maintain(u, d);
return;
} int mid = (lc[u] + rc[u]) / 2;
if (l <= mid)
modify(lson(u), l, r, d);
if (r > mid)
modify(rson(u), l, r, d);
pushup(u);
} struct Seg {
ll x, l, r, d;
Seg (ll x = 0, ll l = 0, ll r = 0, ll d = 0) {
this->x = x;
this->l = l;
this->r = r;
this->d = d;
}
friend bool operator < (const Seg& a, const Seg& b) {
return a.x < b.x;
}
}; int N, W, H;
vector<ll> pos;
vector<Seg> vec; inline int find (ll k) {
return lower_bound(pos.begin(), pos.end(), k) - pos.begin();
} void init () {
ll x, y, d; pos.clear();
vec.clear();
for (int i = 0; i < N; i++) {
scanf("%lld%lld%lld", &x, &y, &d);
pos.push_back(y - H);
pos.push_back(y);
vec.push_back(Seg(x - W, y - H, y, d));
vec.push_back(Seg(x, y - H, y, -d));
}
sort(pos.begin(), pos.end());
sort(vec.begin(), vec.end());
} ll solve () {
ll ret = 0;
build (1, 0, pos.size()); for (int i = 0; i < vec.size(); i++) {
modify(1, find(vec[i].l), find(vec[i].r) - 1, vec[i].d);
ret = max(ret, s[1]);
}
return ret;
} int main () {
while (scanf("%d%d%d", &N, &W, &H) == 3) {
init();
printf("%lld\n", 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 + 51Nod1208(扫描线+离散化+线段树)

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

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

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

  5. POJ 2482 Stars in Your Window(扫描线+线段树)

    [题目链接] http://poj.org/problem?id=2482 [题目大意] 给出一些点的二维坐标和权值,求用一个长H,宽W的矩形能框住的最大权值之和, 在矩形边缘的点不计算在内 [题解] ...

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

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

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

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

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

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

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

    题目链接 非常不容易的一道题,把每个点向右上构造一个矩形,将问题转化为重合矩形那个亮度最大,注意LL,注意排序. #include <cstdio> #include <cstrin ...

随机推荐

  1. ASP.NET Core MVC Hello World

    ASP.NET Core 现在ASP.NET Core还在不断成长.更新中,说不定到了明天又换了个模样,就如同一个小孩,从蹒跚学步,到奔向未来. 所以我们可以相应的去理解更新中所发生的变化,包容它.呵 ...

  2. leetCode Min Stack解决共享

    原标题:https://oj.leetcode.com/problems/min-stack/ Design a stack that supports push, pop, top, and ret ...

  3. Android DrawerLayout 抽屉

    Android DrawerLayout 抽屉 DrawerLayout 在supportV4 Lib在.类似的开源slidemenu如,DrawerLayout父类ViewGroup,自定义组件基本 ...

  4. zoj 2874 &amp; poj 3308 Paratroopers (最小割)

    意甲冠军: 一m*n该网络的规模格.详细地点称为伞兵着陆(行和列). 现在,在一排(或列) 安装激光枪,激光枪可以杀死线(或塔)所有伞兵.在第一i安装一排 费用是Ri.在第i列安装的费用是Ci. 要安 ...

  5. zerglurker的c语言教程006——第一功能

    行,以往的经验教训后,.成员main性能.变数.命名等基本概念应该有一个初步的了解 下面,我们就可以开始我们自己的第一个定义的函数. 仿照头等舱.操作的第二个教训.添加一个新的项目的解决方案Lessi ...

  6. WPF绘制党徽(立体效果,Cool)

    原文:WPF绘制党徽(立体效果,Cool) 前面用WPF方式绘制了党旗(WPF制作的党旗) ,去年3月份利用C# 及GDI+绘制过党徽,这次使用WPF来绘制党徽. ------------------ ...

  7. [INS-32052] Oracle基文件夹和Oracle主文件夹位置同样

    1.错误描写叙述 [INS-32052] Oracle基文件夹和Oracle主文件夹位置同样 2.错误原因    Oracle基文件夹和Oracle主文件夹位置同样 3.解决的方法    Oracle ...

  8. 手提wifi双卡配置+window7同时多用户远程+有些公司限制网络环境方案

    该公司只提供几台机器,同时限制并连接到内部办公网络的机, 我们更多的临时工作人员,项目紧张,而另一种是太麻烦了申请, 当被问及其他网络管理,说没有变通方法. 在我的尝试,最后,找到一个解决方案; 解决 ...

  9. iOS 9 新特性

    这篇文章介绍了iOS9开发相关的简介,现在发布的设备都会搭载iOS9.这篇文章也列出了详细描述新特性的文章. iPad多线程增强 iOS9使用Slider Over, Split View, Pict ...

  10. javascript中的“向量”

    什么是向量 向量通常指一个有长度有方向的量.向量使所有的移动和空间行为更容易理解和在代码中实现.向量可以相加,缩放,旋转,指向某物体. 在javascript中,一个方向和长度(即向量)在二维空间中可 ...