poj 2482 Stars in Your Window(扫描线)
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(扫描线)的更多相关文章
- 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 [题目大意] 给出一些点的二维坐标和权值,求用一个长H,宽W的矩形能框住的最大权值之和, 在矩形边缘的点不计算在内 [题解] ...
- POJ 2482 Stars in Your Window (线段树区间合并+扫描线)
这题开始一直被矩形框束缚了,想法一直都是枚举线,但是这样枚举都需要O(n^2)...但是看了别人的思路,感觉这题思想真心很好(PS:开头好浪漫的描述啊,可惜并没有什么用) 题意就是在平面上给你一些星 ...
- POJ 2482 Stars in Your Window (线段树+扫描线+区间最值,思路太妙了)
该题和 黑书 P102 采矿 类似 参考链接:http://blog.csdn.net/shiqi_614/article/details/7819232http://blog.csdn.net/ts ...
- poj 2482 Stars in Your Window (线段树扫描线)
题目大意: 求一个窗体覆盖最多的星星的权值. 思路分析: 每个星星看成 左下点为x y 右上点为x+w-1 y+h-1 的矩形. 然后求出最大覆盖的和. #include <cstdio> ...
- POJ 2482 Stars in Your Window(线段树+扫描线)
题目链接 非常不容易的一道题,把每个点向右上构造一个矩形,将问题转化为重合矩形那个亮度最大,注意LL,注意排序. #include <cstdio> #include <cstrin ...
随机推荐
- Redis安装及简单測试
摘要: Redis是眼下业界很受到欢迎的一个内存数据库,一般用作系统的中间缓存系统,用以提升总体商业系统的吞吐量和响应速度.本文将简要介绍安装的主要过程以及给出一个简要的測试代码. 1. 系统环境和 ...
- Blink: Chromium的新渲染引擎
编自http://www.chromium.org/blink 关于blink Google Chrome/Chromium 从创始至今一直使用 WebKit(WebCore) 作为 HTML/CSS ...
- [置顶] android系统如何在静音模式下关闭camera拍照声音(2)
之前写过一篇“android系统如何在静音模式下关闭camera拍照声音”的博客,今天来写他的续篇,继续探讨这个问题. 公司新需求,要求在camera应用中添加一个开关,可以进行拍照声音的关闭和开启. ...
- easyui LinkButton
http://www.zi-han.net/case/easyui/menu&button.html
- c++ 计算程序运行时间
转载 http://blog.csdn.net/trustbo/article/details/10582287 以前经常听人提起如何计算程序运行时间,给出一系列函数,当时没有注意,随便选了clock ...
- cocos2d-x学习过程中的疑问
1.一个Scene中不同的层或者有几层Layer是在什么时候设置的? 2.helloWord中init()函数是有谁来调用的? 答:HelloWorld的init函数是在create函数调用后才会调用 ...
- lsb_release: command not found 解决方法(转)
问题:通过lsb_release -a 是查看linux系统版本时报错,具体的解决办法如下: [root@localhost ~]# lsb_release -a-bash: lsb_release: ...
- 高速理解掌握node.js 字符编码,确码过程 以及base64编解码原理
var buf1 = new Buffer('a','ascii'); // 字符'a' -> ascii编码 -> 61 存在计算机中 console.log(buf1); var b ...
- 【C语言探索之旅】 第二部分第十课:练习题和习作
内容简介 1.课程大纲 2.第二部分第十一课: 练习题和习作 3.第三部分第一课预告: 安装SDL 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会公布答案.还会带大家用C语言 ...
- JComboBox
package swing.combox; import java.awt.FlowLayout; import javax.swing.DefaultComboBoxModel; import ja ...