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. LeetCode(113) Path Sum II

    题目 Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given ...

  2. poj 3783

    Balls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1196   Accepted: 783 Description ...

  3. H.264基本原理与编码流程

    H264视频压缩算法现在无疑是所有视频压缩技术中使用最广泛,最流行的.随着 x264/openh264以及ffmpeg等开源库的推出,大多数使用者无需再对H264的细节做过多的研究,这大降低了人们使用 ...

  4. PAT Basic 1069

    1069 微博转发抽奖 小明 PAT 考了满分,高兴之余决定发起微博转发抽奖活动,从转发的网友中按顺序每隔 N 个人就发出一个红包.请你编写程序帮助他确定中奖名单. 输入格式: 输入第一行给出三个正整 ...

  5. saltstack管理八之常用执行模块

    所有执行模块: http://docs.saltstack.cn/zh_CN/latest/ref/states/all/index.html 常用模块:cmd, cron, file, mount, ...

  6. OpennSSL之基本了解

    HTTPS是一种协议,等于HTTP+TLS(由于历史原因,SSL3.0之后就被TLS1.0替代了).openssl是一套开源工具集,主要有两个特性: 实现了ssl2,ssl3,TLSv1,TLSv1. ...

  7. Matplotlib基本图形之折线图

    Matplotlib基本图形之折线图折线图特点 折线图是用折线将各数据连起来组成的图形常用来观察数据随时间变化的趋势例如:股票价格,温度变化,等等 示例代码: import os import tim ...

  8. APP版本升级

    /*** version_upgrade 版本升级信息表*/CREATE TABLE `version_upgrade` ( `id` smallint(4) unsigned NOT NULL AU ...

  9. 【LeetCode】Integer to Roman(整数转罗马数字)

    这道题是LeetCode里的第12道题. 吐了,刚做完"罗马数字转整数",现在又做这个.这个没什么想法,只能想到使用if语句嵌套,或者使用哈希表.但哈希表我还不熟练啊.先拿if嵌套 ...

  10. 图论trainning-part-2 B. Claw Decomposition

    B. Claw Decomposition Time Limit: 1000ms Memory Limit: 131072KB 64-bit integer IO format: %lld      ...