[POI 2001+2014acm上海邀请赛]Gold Mine/Beam Cannon 线段树+扫描线
- 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.
(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.
#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 线段树+扫描线的更多相关文章
- 线段树+扫描线 HDOJ 5091 Beam Cannon(大炮)
题目链接 题意: 给出若干个点的坐标,用一个W*H的矩形去覆盖,问最多能覆盖几个点. 思路: 这是2014上海全国邀请赛的题目,以前写过,重新学习扫描线.首先把所有点移到第一象限([0, 40000] ...
- 2014ACM上海邀请赛A解释称号
#include <cstdio> #include <cstring> #include <iostream> using namespace std; cons ...
- POI 2001 Goldmine 线段树 扫描线
题目链接 http://www.acm.cs.ecnu.edu.cn/problem.php?problemid=1350 http://main.edu.pl/en/archive/oi/8/kop ...
- USACO 2008 Nov Gold 3.Light Switching 线段树
Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ...
- 2019ICPC上海网络赛A 边分治+线段树
题目: 给定一棵树, 带边权. 现在有2种操作: 1.修改第i条边的权值. 2.询问u到其他一个任意点的最大距离是多少. 解法:边分治+线段树 首先我们将所有的点修改和边修改都存在对应的边里面. 然后 ...
- HDOJ 5091 Beam Cannon 扫描线
线段树+扫描线: 我们用矩形的中心点来描写叙述这个矩形,然后对于每一个敌舰,我们建立一个矩形中心的活动范围,即矩形中心在该范围内活动就能够覆盖到该敌舰.那么我们要求的问题就变成了:随意一个区域(肯定也 ...
- hdu 5091 Beam Cannon(扫描线段树)
题目链接:hdu 5091 Beam Cannon 题目大意:给定N个点,如今要有一个W∗H的矩形,问说最多能圈住多少个点. 解题思路:线段的扫描线,如果有点(x,y),那么(x,y)~(x+W,y+ ...
- HDU 5091 Beam Cannon (扫描线思想)
题意:移动一个矩形,使矩形内包含的点尽量多. 思路:把一个点拆成两个事件,一个进(权值为1)一个出(权值为-1),将所有点按照x排序,然后扫描,对于每个x,用一个滑窗计算一下最大值,再移动扫描线.树状 ...
- 2018 ACMICPC上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节) 链接:https://ac.nowcoder.co ...
随机推荐
- uboot顶层mkconfig分析
GNU make:http://www.gnu.org/software/make/manual/make.html#Rules 为了便于理解把uboot中的Makefile配置部分弄出来便于理解,这 ...
- PAT Basic 1066
1066 图像过滤 图像过滤是把图像中不重要的像素都染成背景色,使得重要部分被凸显出来.现给定一幅黑白图像,要求你将灰度值位于某指定区间内的所有像素颜色都用一种指定的颜色替换. 输入格式: 输入在第一 ...
- PAT Basic 1045
1045 快速排序 著名的快速排序算法里有一个经典的划分过程:我们通常采用某种方法取一个元素作为主元,通过交换,把比主元小的元素放到它的左边,比主元大的元素放到它的右边. 给定划分后的 N 个互不相同 ...
- leetcode刷题——查找
知识点 备忘-必备算法 题目 顺序查找 二分查找 树表搜索 广度优先搜索算法(BFS) 深度优先搜索算法(DFS) 回溯(Backtracking) 题解 CS-Notes Algorithm_Int ...
- 爬虫开发python工具包介绍 (1)
本文来自网易云社区 作者:王涛 本文大纲: 简易介绍今天要讲解的两个爬虫开发的python库 详细介绍 requests库及函数中的各个参数 详细介绍 tornado 中的httpcilent的应用 ...
- Cocos2d-JS 实现将TiledMap中的每个 tile 变成物理精灵的方法
How to generate a physics body from a tiledmap 鄙人在网上找了许久都未找到方法,说句实在话,Cocos2d官方给出的与物理引擎相关的内容真的不是很多, ...
- 2017 ACM/ICPC Asia Regional Shenyang Online
cable cable cable Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- ubuntu添加开机启动
vim /etc/init.d/mytest #!/bin/sh echo "$(pwd) and $USER and $(whoami)" >> /root/temp ...
- 【UML】UML图的发展和体系结构
导读:上次给徒弟验收UML的项目,在验收的时候提出了很多问题,徒弟也暴露了一些问题.说好我们一起总结成长的,由于最近的事儿,比较忙,所以现在进行总结.上次会议中说到要用门卫思维去总结这部分的知识点,用 ...
- [Kubernetes]容器健康检查和恢复机制
在Kubernetes中,可以为Pod里的容器定义一个健康检查探针(Probe),这样Kubernetes会根据这个Probe的返回值决定这个容器的状态,而不是直接以容器是否允许(来自Docker返回 ...