POI 2001 Goldmine 线段树 扫描线
题目链接
http://www.acm.cs.ecnu.edu.cn/problem.php?problemid=1350
http://main.edu.pl/en/archive/oi/8/kop
求平面n个点(n<=15000),用一个 长宽为 s w的矩阵去套,能套到的最多的点数,在边上的点也算
其实跟之前矩形嵌套求面积类似 (POJ的atlantic)用类似扫描线的做法,把点当做边 (y 到 y值+w),插入线段树,这样就维护了y方向,x方向就用类似队列维护,
在距离大于s的时候,就弹出前面的(即线段树移除那条边),一边添加当前边
维护一个值,看从前扫到后,边层数累积的最多的时候即可。
一开始还以为要维护覆盖值,后来发现没用,直接一个d维护积累层数即可。
一开始输入那里没写好EOF,RE了几次,不知道什么原因,改完之后1A
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
using namespace std;
const int N = 100020;
//int cover[N<<2];
int flag[N<<2];
int d[N<<2];
int s,w,n,maxn;
struct node{
int x,y;
bool operator < (const node& rhs ) const{
if (x==rhs.x) return y<rhs.y;
return x<rhs.x;
}
}point[15010];
bool input()
{
maxn=0;
if (scanf("%d%d",&s,&w)==EOF) return false;
scanf("%d",&n);
for (int i=1;i<=n;i++){
scanf("%d%d",&point[i].x,&point[i].y);
point[i].x+=30000;
point[i].y+=30000;
maxn=max(maxn,point[i].y);
}
maxn+=w+10;
return true;
}
void build(int rt,int l,int r)
{
//cover[rt]=0;
flag[rt]=0;
d[rt]=0;
if (l>=r) return;
int mid=(l+r)>>1;
build(lson);
build(rson);
}
void pushdown(int rt,int l,int r)
{
if (flag[rt]==0) return;
int mid=(l+r)>>1;
//cover[rt<<1]+=flag[rt]*(mid-l+1);
//cover[rt<<1|1]+=flag[rt]*(r-mid);
d[rt<<1]+=flag[rt];
d[rt<<1|1]+=flag[rt];
flag[rt<<1]+=flag[rt];
flag[rt<<1|1]+=flag[rt];
flag[rt]=0;
}
void up(int rt)
{
//cover[rt]=cover[rt<<1]+cover[rt<<1|1];
d[rt]=max(d[rt<<1],d[rt<<1|1]);
}
void remove(int L,int R,int rt,int l,int r)
{
if (L<=l && r<=R){
//cover[rt]-=(r-l+1);
d[rt]--;
flag[rt]+=-1;
return;
}
pushdown(rt,l,r);
int mid=(l+r)>>1;
if (L<=mid) remove(L,R,lson);
if (R>mid) remove(L,R,rson);
up(rt);
}
void inserts(int L,int R,int rt,int l,int r)
{
if (L<=l && r<=R){
//cover[rt]+=(r-l+1);
d[rt]++;
flag[rt]+=1;
return ;
}
pushdown(rt,l,r);
int mid=(l+r)>>1;
if (L<=mid) inserts(L,R,lson);
if (R>mid) inserts(L,R,rson);
up(rt);
}
int main()
{
while (input()){
sort(point+1,point+1+n);
build(1,0,maxn);
int pre=1;
int ans=0;
for (int i=1;i<=n;i++){
//cout<<i<<endl;
while (point[pre].x+s<point[i].x){
remove(point[pre].y,point[pre].y+w,1,0,maxn);
pre++;
}
inserts(point[i].y,point[i].y+w,1,0,maxn);
ans=max(ans,d[1]);
}
printf("%d\n",ans);
}
}
POI 2001 Goldmine 线段树 扫描线的更多相关文章
- 【Codeforces720D】Slalom 线段树 + 扫描线 (优化DP)
D. Slalom time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)
题目链接:http://codeforces.com/contest/522/problem/D 题目大意: 给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- HDU 4419 Colourful Rectangle --离散化+线段树扫描线
题意: 有三种颜色的矩形n个,不同颜色的矩形重叠会生成不同的颜色,总共有R,G,B,RG,RB,GB,RGB 7种颜色,问7种颜色每种颜色的面积. 解法: 很容易想到线段树扫描线求矩形面积并,但是如何 ...
- BZOJ-3228 棋盘控制 线段树+扫描线+鬼畜毒瘤
3228: [Sdoi2008]棋盘控制 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 23 Solved: 9 [Submit][Status][D ...
- BZOJ-3225 立方体覆盖 线段树+扫描线+乱搞
看数据范围像是个暴力,而且理论复杂度似乎可行,然后被卡了两个点...然后来了个乱搞的线段树+扫描线.. 3225: [Sdoi2008]立方体覆盖 Time Limit: 2 Sec Memory L ...
- hdu 5091(线段树+扫描线)
上海邀请赛的一道题目,看比赛时很多队伍水过去了,当时还想了好久却没有发现这题有什么水题的性质,原来是道成题. 最近学习了下线段树扫描线才发现确实是挺水的一道题. hdu5091 #include &l ...
- POJ1151+线段树+扫描线
/* 线段树+扫描线+离散化 求多个矩形的面积 */ #include<stdio.h> #include<string.h> #include<stdlib.h> ...
- POJ-1151-Atlantis(线段树+扫描线+离散化)[矩形面积并]
题意:求矩形面积并 分析:使用线段树+扫描线...因为坐标是浮点数的,因此还需要离散化! 把矩形分成两条边,上边和下边,对横轴建树,然后从下到上扫描上去,用col表示该区间有多少个下边,sum代表该区 ...
随机推荐
- java中使用静态字段和构造函数跟踪某个类所创建对象的个数
对于这个问题,我们都知道java中使用类时会自动调用构造函数.按照这个思路我们可以定义一个static int 形的常量count 然后将count++放入这个类的构造函数中,这样只要输出count的 ...
- 关于找不到指定的模块,异常来自HRESULT:0x8007007E的解决方法
上午从公司前辈那里拷贝到的ASP.NET代码,在自己机器上部署的时候发现问题,直接报错,找不到指定的模块,异常来自HRESULT:0x8007007E.并且一大堆警告. 在网上百度很多解决方法,归纳如 ...
- for in 与for 与hasOwnProperty
在遍历一个对象的时候我们会使用到for in属性. 现有对象和数组如下: var filght = { number: 1, status: 'watit', arrival: [1,2,3], ad ...
- php 算法知识 冒泡排序
function bubble_order($arr){ //得到长度 $count_num=count($arr); for($k=1;$k<$count_num;$k++){ //对长度越来 ...
- 操作系统OS - 反置页表
1. https://blog.csdn.net/wuyuegb2312/article/details/16359821 2. https://www.youtube.com/watch?v=YQ3 ...
- 变量的注释(python3.6以后的功能)
有时候导入模块,然后使用这个变量的时候,却没点出后面的智能提示.用以下方法可以解决:https://www.cnblogs.com/xieqiankun/p/type_hints_in_python3 ...
- Qt5.5 使用smtp发邮件的各种坑
本人刚开始学习C++,用的是Qt5.5的IED,经过了两天的学习和查找资料,终于成功发了第一封邮件.以163邮箱为例,简单总结一下. 1.设置邮箱 这一步比较关键,要开通smtp服务,在开通的过程中会 ...
- 3 CSS 定位&浮动&水平对齐&组合选择符&伪类&伪元素
CSS Position(定位):元素的定位与文档流无关 static定位: HTML元素的默认值, 没有定位,元素出现在正常的流中 静态定位的元素不会受到top,bottom,left,right影 ...
- 都客仿站高手已注册旗舰版V3.1
链接:https://pan.baidu.com/s/1R5ldFDjekuXmEp42-8SQSQ 提取码:gkm9
- SpringBoot 获得 properties 文件中数据方式
参考:https://blog.csdn.net/qq_37171353/article/details/78005845