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. solr 日志配置

    配置Solr日志记录 临时记录设置 您可以使用Admin Web界面来控制Solr中的日志输出量.选择LOGGING链接.请注意,此页面只允许您更改正在运行的系统中的设置,并不会保存在下一次​​运行中 ...

  2. ACM训练联盟周赛 G. Teemo's convex polygon

    65536K   Teemo is very interested in convex polygon. There is a convex n-sides polygon, and Teemo co ...

  3. PAT Basic 1021

    1021 个位数统计 给定一个k位整数N = d~k-1~*10^k-1^ + ... + d~1~*10^1^ + d~0~ (0<=d~i~<=9, i=0,...,k-1, d~k- ...

  4. 封装微信分享到朋友/朋友圈js

    在页面引入: <script src="/static/lib/jquery-2.2.2.min.js"></script><script src=& ...

  5. HTML与XML的区别

    什么是HTML HTML的全拼是Hypertext Markup Language, 中文也就是超文本链接标示语言.HTML(HyperTextMark-upLanguage)即超文本标记语言,是WW ...

  6. 面试准备——Zookeeper

    转自https://www.cnblogs.com/shan1393/p/9479109.html 1. Zookeeper是什么框架 分布式的.开源的分布式应用程序协调服务,原本是Hadoop.HB ...

  7. IE浏览器部分js代码不生效的问题

    [小小坑记录] 问题描述:IE浏览器写好功能代码之后,在调试模式下程序能正常运行.不开启调试模式正常访问时js部分功能代码不生效. 原因:在测试时用了console对象在控制台输出一一些内容,而IE的 ...

  8. CentOS下,mysql服务启动失败

    mysql服务启动失败,可以使用排除法查找原因: 如果修改了my.cnf后重启mysql服务失败,大多数情况下都是配置文件有错误, 可以通过备份原来的配置文件,然后将配置文件清空,只剩下[mysqld ...

  9. A. Light Bulb

    A. Light Bulb Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 32768KB   64-bit integer IO f ...

  10. tomcat的管理(manager)报错403

    管理tomcat的时候遇到了以下问题: 1.刚开始需要用户名密码,不知道用户名和密码是什么,但是输入什么都不正确. 解决办法: 自己在tomcat-users.xml中按格式添加用户 conf文件夹里 ...