Description 

Byteman, one of the most deserving employee of The Goldmine of Byteland, is about to retire by the end of the year. The Goldmine management would like to reward him in acknowledgment of his conscientious work. As a reward Byteman may receive a small lot
- a rectangular piece of the mine's area with sides of length s and w parallel to the axes of the coordinate system. He may choose the location of the lot. Of course, a value of the lot depends on the location. The value of the lot is a number of gold nuggets
in the area of the lot (if a nugget lies on the border of the lot, then it is in the area of the lot). Your task is to write a program which computes the maximal possible value of the lot (the value of the lot with the best location). In order to simplify
we assume that the terrain of the Goldmine is boundless, but the area of gold nuggets occurrence is limited. 

Task
Write a program which:

1.reads the location of gold nuggets, 
2.computes the maximal value of a lot (i.e. the maximal number of gold nuggets on the lot of given size), 
3.writes the result . 
Input 

In the first line there are two positive integers s and w separated by a single space, (1<=s,w<=10 000); they denote the lengths of lot's sides - parallel to the OX-axe and OY-axe respectively. There is one positive integer n written in the second line,
(1<=n<=15 000). It denotes the number of nuggets in the area of the Goldmine. In the following n lines there are written the coordinates of the nuggets. Each of these lines consists of two integers x and y, (-30 000<=x,y<=30 000), separated by a single space
and denoting the x and the y coordinate of a nugget respectively.

Output 

The out should contain exactly one integer equal to the value of the most valuable lot of a given size.

Sample Input 

1 2
12
0 0
1 1
2 2
3 3
4 5
5 5
4 2
1 4
0 5
5 0
2 3
3 2

Sample Output 

4



题目大意

给定二维平面上的N个点,寻找一个w*s(高w宽s,被这个点坑好久)的矩形,使得当中包括最多的点。

上海邀请赛B题的题意和这一题类似。



思路

黑书原题。

将每个点看作是两个事件从左到右进行扫描(能够维护队列控制队头和队尾的差不超过宽度,也能够依照时间顺序排序后进行处理),每个点抽象成长度为矩形高度的线段,线段经过次数最多的点便是结果。

这样就把O(n^2)降维至O(n*log(A)),A为点纵坐标的范围。

在这里能够提交

http://acm.cs.ecnu.edu.cn/problem.php?problemid=1350

ps:太弱了,不仅当场没出这道题并且后来做的时候还W一天,基础还是有待夯实啊。
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <vector>
#include <cstring>
using namespace std;
struct node{
int t,pos,st;
}ha[200000];
int x1,x2,v;
int _max;
int n,w,h;
int cmp(node x,node y)
{
return (x.t<y.t);//依照时间先后顺序排序,先删除点再加入点
}
int maxv[400000],addv[400000];
void maintain(int o,int L,int R)
{
int lc=o<<1;
int rc=lc+1;
maxv[o]=0;
if (R>L)
{
maxv[o]=max(maxv[lc],maxv[rc]);
}
maxv[o]+=addv[o];
}
void update(int o,int L,int R)
{
int lc=o<<1;
int rc=lc+1;
if (x1<=L&&x2>=R) addv[o]+=v;
else {
int M=L+(R-L)/2;
if (x1<=M) update(lc,L,M);
if (x2>M) update(rc,M+1,R);
}
maintain(o,L,R);
}
void query(int o,int L,int R,int add)
{
int lc=o<<1;
int rc=lc+1;
if (x1<=L&&x2>=R) _max=max(_max,maxv[o]+add);
else {
int M=L+(R-L)/2;
if (x1<=M) query(lc,L,M,addv[o]+add);
if (x2>M) query(rc,M+1,R,addv[o]+add);
}
}
int main()
{
while(~scanf("%d%d%d",&w,&h,&n))
{
memset(maxv,0,sizeof(maxv));
memset(addv,0,sizeof(addv));
_max=0;
int o,p,pt=0;
memset(ha,0,sizeof(ha));
for (int i=1;i<=n;i++)
{
scanf("%d%d",&o,&p);
ha[++pt].t=o;
ha[pt].pos=p+30001;
ha[pt].st=1;
ha[++pt].t=o+w+1;
ha[pt].pos=p+30001;
ha[pt].st=-1;
}
sort(ha+1,ha+pt+1,cmp);//将全部时间点排序
for (int i=1;i<=pt;i++)
{
x1=ha[i].pos;
x2=ha[i].pos+h;
x2=min(x2,60001);
v=ha[i].st;
update(1,1,60001);//更新点数
if (ha[i].t!=ha[i+1].t||i==pt)//直至同一时间点的全部更新完毕之后才输出
{
x1=1;
x2=60001;
query(1,1,60001,0);
}
}
printf("%d\n",_max);
}
}


[POI 2001+2014acm上海邀请赛]Gold Mine/Beam Cannon 线段树+扫描线的更多相关文章

  1. 线段树+扫描线 HDOJ 5091 Beam Cannon(大炮)

    题目链接 题意: 给出若干个点的坐标,用一个W*H的矩形去覆盖,问最多能覆盖几个点. 思路: 这是2014上海全国邀请赛的题目,以前写过,重新学习扫描线.首先把所有点移到第一象限([0, 40000] ...

  2. 2014ACM上海邀请赛A解释称号

    #include <cstdio> #include <cstring> #include <iostream> using namespace std; cons ...

  3. POI 2001 Goldmine 线段树 扫描线

    题目链接 http://www.acm.cs.ecnu.edu.cn/problem.php?problemid=1350 http://main.edu.pl/en/archive/oi/8/kop ...

  4. USACO 2008 Nov Gold 3.Light Switching 线段树

    Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ...

  5. 2019ICPC上海网络赛A 边分治+线段树

    题目: 给定一棵树, 带边权. 现在有2种操作: 1.修改第i条边的权值. 2.询问u到其他一个任意点的最大距离是多少. 解法:边分治+线段树 首先我们将所有的点修改和边修改都存在对应的边里面. 然后 ...

  6. HDOJ 5091 Beam Cannon 扫描线

    线段树+扫描线: 我们用矩形的中心点来描写叙述这个矩形,然后对于每一个敌舰,我们建立一个矩形中心的活动范围,即矩形中心在该范围内活动就能够覆盖到该敌舰.那么我们要求的问题就变成了:随意一个区域(肯定也 ...

  7. hdu 5091 Beam Cannon(扫描线段树)

    题目链接:hdu 5091 Beam Cannon 题目大意:给定N个点,如今要有一个W∗H的矩形,问说最多能圈住多少个点. 解题思路:线段的扫描线,如果有点(x,y),那么(x,y)~(x+W,y+ ...

  8. HDU 5091 Beam Cannon (扫描线思想)

    题意:移动一个矩形,使矩形内包含的点尽量多. 思路:把一个点拆成两个事件,一个进(权值为1)一个出(权值为-1),将所有点按照x排序,然后扫描,对于每个x,用一个滑窗计算一下最大值,再移动扫描线.树状 ...

  9. 2018 ACMICPC上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节) 链接:https://ac.nowcoder.co ...

随机推荐

  1. SpringBoot 多线程

    Spring通过任务执行器(TaskExecutor)来实现多线程和并发编程.使用ThreadPoolTaskExecutor可实现一个基于线程池的TaskExecutor.而实际开发中任务一般是非阻 ...

  2. 算法学习记录-排序——选择排序(Simple Selection Sort)

    之前在冒泡排序的附录中提到可以在每次循环时候,不用交换操作,而只需要记录最小值下标,每次循环后交换哨兵与最小值下标的书, 这样可以减少交换操作的时间. 这种方法针对冒泡排序中需要频繁交换数组数字而改进 ...

  3. grunt与seajs结合应用

    9.seajs构建的问题 01.png和02.jpg 10.seajs与grunt如何结合开发.两个插件:grunt-cmd-transport grunt-cmd-contact ,去grunt官网 ...

  4. oracle11gR2下scott用户以及表的建立

    目录 oracle11gR2下scott用户以及表的建立 找到系统带的sql文件(utlsample.sql) 根据SQL的内容操作 新建用户并授权 scott登录 表操作 查询表(使用pl/sql) ...

  5. GT使用说明

    GT文档:https://gt.qq.com/docs.html GT Android版的详细使用手册: https://gt.qq.com/docs/a/GTAndroidUserGuide.pdf

  6. Linux 文件/文件夹重命名

    mv命令既可以重命名,又可以移动文件或文件夹. 例子:将目录A重命名为Bmv A B 例子:将/a目录移动到/b下,并重命名为cmv /a /b/c 其实在文本模式中要重命名文件或目录,只需要使用mv ...

  7. Educational Codeforces Round 33 (Rated for Div. 2)

    A. Chess For Three time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. MHA 高可用集群搭建(二)

    MHA 高可用集群搭建安装scp远程控制http://www.cnblogs.com/kevingrace/p/5662839.html yum install openssh-clients mys ...

  9. Oracle 查看 使用 UNDO 段的事务脚本

    查看oracle undo segment段的信息: SELECT T1.USN, T2.NAME, T1.STATUS, T1.LATCH, T1.EXTENTS, T1.WRAPS, T1.EXT ...

  10. 【Luogu】P3384主席树模板(主席树查询K小数)

    YEAH!我也是一个AC主席树模板的人了! 其实是个半吊子 我将尽量详细的讲出我的想法. 主席树太难,我们先搞普通线段树好了 普通线段树怎么做?我的想法是查询K次最小值,每次查完把查的数改成INF,查 ...