[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 ...
随机推荐
- wordcloud的安装报错 error: Microsoft Visual C++ 10.0 is required. Get it with "Microsoft Windows SDK 7.1"解决办法
cmd中使用pip install wordcloud失败,没看懂报错的原因…… 而在pycharm中添加也报错 解决方法: 1. 下载wordcloud-1.4.1.tar.gz,解压缩 cmd c ...
- BIOM Table-codes
import numpy from biom.table import Table ========================================================== ...
- JavaScript正则表达式-非捕获性分组
非捕获性分组定义子表达式可以作为整体被修饰但是子表达式匹配结果不会被存储. 非捕获性分组通过将子表达式放在"?:"符号后. str = "img1.jpg,img2.jp ...
- 03006_Servlet简介
1.什么是Servlet (1)Servlet 运行在服务端的Java小程序,是sun公司提供一套规范(接口),用来处理客户端请求.响应给浏览器的动态资源: (2)Servlet的实质就是java代码 ...
- linux 第五部分 系统管理员 网络设定与备份
linux 第五部分 系统管理员 网络设定与备份 系统基本设置 1.网络的设置 手动设置与dhcp自动获得 以及更改主机名称 centos 7 对网卡编号的规则 enol1 b ...
- numpy hstack()
numpy.hstack(tup)[source] Stack arrays in sequence horizontally (column wise). Take a sequence of ar ...
- Codeforces Round #265 (Div. 1)
D. World of Darkraft - 2 time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 【UML】关联、依赖、泛化、实现等关系说明
导读:再上一篇博客中,介绍了UML的9种图,现在,将对UML中的关系进行总结.图很重要,但图形中的各种关系也很重要,这扯关系的事儿,从来都是大事儿. 一.基本定义 1.1 总体说明 1.2 具体定义 ...
- 九度oj 题目1151:位操作练习
题目描述: 给出两个不大于65535的非负整数,判断其中一个的16位二进制表示形式,是否能由另一个的16位二进制表示形式经过循环左移若干位而得到. 循环左移和普通左移的区别在于:最左边的那一位经过循环 ...
- iOS学习笔记16-数据库SQLite
一.数据库 在项目开发中,通常都需要对数据进行离线缓存的处理,如新闻数据的离线缓存等.离线缓存一般都是把数据保存到项目的沙盒中.有以下几种方式: 归档:NSKeyedArchiver 偏好设置:NSU ...