POI2001 金矿
问题描述
金矿的老师傅年底要退休了。经理为了奖赏他的尽职尽责的工作,决定在一块包含 n(n ≤ 15000) 个采金点的长方形土地中划出一块长度为 S ,宽度为 W 的区域奖励给他(1 ≤ s , w ≤ 10 000)。老师傅可以自己选择这块地的位置,显然其 中包含的采金点越多越好。你的任务就是计算最多能得到多少个采金点。如果一个采金点的位置在长方形的边上,它也应当被计算在内。
输入格式
输入文件的第一行有两个整数,中间用一个空格隔开,表示长方形土地的长和宽即s和w(1<=s,w<=10 000)。第二行有一个整数n(1<=n<=15 000),表示金矿数量。下面的n行与金矿相对应,每行两个整数x和y (-30 000<=x,y<=30 000),中间用一个空格隔开,表示金矿的坐标。
输出格式
输出文件只有一个整数,表示选择的最大金矿的数。
------------------------------------------------------------
正解=离散化+平衡树
点比坐标小的多,离散之- =
要求一个宽 s 长 w的且覆盖点最多的矩形
维护一个宽度为 s 的带状区间 既满足宽度限制
建立以y为关键字的平衡树维护之
我们要求的既长度h的区间中的最大值
将一个点x,y 拆成两个点
x,y,权值为1
x,y+h+1权值为-1
维护一个这样的以y为第一关键字,权值为第二关键字的平衡树
最大前缀和既长度h的区间中的最大值(Orz神差分前缀求和)
代码如下:
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<map>
#include<queue>
#define LL long long
#define INF 999999999
#define Min(num1,num2) if(num1>num2) num1=num2
#define Max(num1,num2) if(num1<num2) num1=num2
#define N 150000
using namespace std ;
struct Point {
int x,y,neg,pos;
}point[N];
bool cmp(const Point &X,const Point &Y){
return X.x<Y.x;
}
struct Tree{
int l,r,f,v1,v2,sum,mmax;
}a[N];
int n,Root,Total,s,w,edge[N],top;
int q[];
void puit(int now){
printf("No.%d L:%d R:%d V1:%d V2:%d Sum:%d Mmax:%d\n",now,a[now].l,a[now].r,a[now].v1,a[now].v2,a[now].sum,a[now].mmax);
}
void update(int now){
// puit(now);
// printf("->\n");
// puit(a[now].l);
// puit(a[now].r);
// printf("-------------------------------\n");
a[now].sum=a[a[now].l].sum+a[a[now].r].sum+a[now].v2;
a[now].mmax=max(a[a[now].l].mmax,a[a[now].l].sum+a[now].v2 );
a[now].mmax=max(a[now].mmax ,a[a[now].l].sum+a[now].v2+a[a[now].r].mmax);
}
void put(int now){
if(a[now].l) put(a[now].l);
printf("%d ",a[now].v1);
//printf("V1%d(V2%d)(Sum%d)(Mmax%d) ",a[now].v1,a[now].v2,a[now].sum,a[now].mmax);
if(a[now].r) put(a[now].r);
}
void rig(int now){
int f=a[now].f;
a[now].f=a[f].f;
if(a[a[f].f].l==f) a[a[f].f].l=now;
if(a[a[f].f].r==f) a[a[f].f].r=now;
a[f].f=now;
a[f].l=a[now].r;
a[a[now].r].f=f;
a[now].r=f;
update(f);
}
void lef(int now){
int f=a[now].f;
a[now].f=a[f].f;
if(a[a[f].f].l==f) a[a[f].f].l=now;
if(a[a[f].f].r==f) a[a[f].f].r=now;
a[f].f=now;
a[f].r=a[now].l;
a[a[now].l].f=f;
a[now].l=f;
update(f);
}
void splay(int now,int F=){
while(a[now].f!=F){
int f=a[now].f;
int ff=a[f].f;
if(ff==F)
if(a[f].l==now)
rig(now);
else
lef(now);
else
if(a[ff].l==f)
if(a[f].l==now)
rig(f),rig(now);
else
lef(now),rig(now);
else
if(a[f].r==now)
lef(f),lef(now);
else
rig(now),lef(now);
}
update(now);
if(!F) Root=now;
}
int insert(int v1,int v2){
for(int now=Root;;){
q[++top]=now;
if(v1<a[now].v1||(v1==a[now].v1&&v2<=a[now].v2))
if(a[now].l) now=a[now].l;
else{
a[now].l=++Total;
a[Total].v1=v1;
a[Total].v2=v2;
a[Total].f=now;
a[Total].sum=v2;
a[Total].mmax=max(v2,);
break;
}
else
if(a[now].r) now=a[now].r;
else{
a[now].r=++Total;
a[Total].v1=v1;
a[Total].v2=v2;
a[Total].f=now;
a[Total].sum=v2;
a[Total].mmax=max(v2,);
break;
}
}
while(top) update(q[top--]);
splay(Total);
// put(Root);
// printf("\n");
return Total;
}
int prev(int now){
splay(now);
now=a[now].l;
while(a[now].r) now=a[now].r;
return now;
}
int succ(int now){
splay(now);
now=a[now].r;
while(a[now].l) now=a[now].l;
return now;
}
void del(int now){
int start=prev(now);
int end=succ(now);
splay(start);
splay(end,Root);
a[a[Root].r].l=;
update(a[Root].r);
update(Root);
}
void removeL(int now){
del(point[now].pos);
del(point[now].neg);
}
void removeR(int now){
point[now].pos=insert(point[now].y ,);
point[now].neg=insert(point[now].y+w+,-);
}
int main(){
scanf("%d%d%d",&s,&w,&n);
for(int i=;i<=n;i++)
scanf("%d%d",&point[i].x,&point[i].y);
sort(point+,point++n,cmp);
point[].x=-INF;
int Maxedge=;
for(int i=;i<=n;i++)
if(point[i].x!=point[i-].x)
edge[++Maxedge]=point[i].x;
int L=,now=,R=,ans=;
Total=;
Root=;
a[].v1=INF;
a[].v1=-INF;
a[].l=;
a[].f=;
while(now<Maxedge){
++now;
while(edge[now]-point[L].x>s&&L <=n) removeL(L),++L;
while(point[R].x==edge[now] &&R <=n) removeR(R),++R;
Max(ans,a[Root].mmax); }
printf("%d",ans);
}
POI2001 金矿的更多相关文章
- POI2001 Gold mine(二叉排序树 黑书经典)
采矿(KOP) 金矿的老师傅年底要退休了.经理为了奖赏他的尽职尽责的工作,决定送他一块长方形地.长度为S,宽度为W.老师傅可以自己选择这块地.显然其中包含的采金点越多越好.你的任务就是计算最多能得到多 ...
- Nginx日志中的金矿 -- 好文收藏
转:http://www.infoq.com/cn/articles/nignx-log-goldmine Nginx(读作Engine-X)是现在最流行的负载均衡和反向代理服务器之一.如果你是一名中 ...
- 【POI2001】【HDU1814】和平委员会
题面 Description 根据宪法,Byteland民主共和国的公众和平委员会应该在国会中通过立法程序来创立. 不幸的是,由于某些党派代表之间的不和睦而使得这件事存在障碍. 此委员会必须满足下列条 ...
- 新一批创业者金矿,iclap谁与争锋
19世纪,美国西部开发,无数拓荒者涌入,并最终因金矿的发现形成了淘金热.而当无数人埋头寻找黄金之时,有一个人却抬起头看到了潜藏在无数淘金者身上的金矿-这个人就是牛仔裤的发明者,Levi’s的创始人-李 ...
- COGS:313. [POI2001] 和平委员会
313. [POI2001] 和平委员会 ★★☆ 输入文件:spo.in 输出文件:spo.out 评测插件时间限制:1 s 内存限制:128 MB 题目描述 根据宪法,Bytelan ...
- [POI2001]Goldmine
Description Byteman作为Byteland的The Goldmine(某一公司厂矿)的最有功的雇员之一,即将在年末退休.为了表示对他的 认真勤恳的工作的承认,The Goldmine的 ...
- 【转帖】PowerPC架构:IBM的一座金矿
PowerPC架构:IBM的一座金矿 https://www.eefocus.com/mcu-dsp/365599 <处理器史话>之十五 2016-07-15 14:01 作者:付丽华预计 ...
- lb开金矿 QDUOJ 数论
lb开金矿 QDUOJ 数论 原题链接,点我进去 题意 大家都知道lb有n个小弟(编号从2到n+1),他们可以按照规则传递信息:某天编号为i的小弟收到信息后,那么第二天他会给编号为j的小弟传达信息,其 ...
- 动态规划-国王的金矿问题java
紧接着上一篇动态规划问题,现在我们开始探讨一个新的问题,问:有一个发现了5个金矿,每一个金矿的储量不同,需要参与挖掘的工人数也不通,参与挖矿工人的总数量是10人,每一座金矿要么全挖,要么不挖,不能派一 ...
随机推荐
- centOS 6.4 vsftpd 500 illegal port command
原先配置好的vsftpd突然不行了,不知为啥,感觉跟网络有关,这个网络总是有dns拦截的现象,..小公司.真烦人,用联通线路就没问题, 但同事就是连不上,我的笔记本却可以连接上..我的ubuntn,同 ...
- shell脚本操作mysql数据库—创建数据库,在该数据库中创建表(插入,查询,更新,删除操作也可以做)
#!/bin/bash HOSTNAME="192.168.1.224" #数据库Server信 ...
- Spring MVC框架理解
原文链接:ITeye SpringMVC深度探险专栏 基本要素 1. 指定SpringMVC的入口程序(在web.xml中) <!-- Processes application request ...
- hadoop1中partition和combiner作用
---恢复内容开始--- 1.解析Partiton 把map任务的输出的中间结果按照key的范围进行划分成r份,r代表reduce任务的个数.hadoop默认有个类HashPartition实现分区, ...
- xe6+firedac连接sybase
一.Win7 X64系统安装sybase odbc: 1. 下载对应包至c:\system_odbc(文件夹名自己取,在后面注册表内容需要用到): 2. 将值信息写入到注册表内: Windows ...
- 点评VHDL语言
(1)VHDL的描述风格及语法十分类似于一般的计算机高级语言,但是它是一种硬件描述语言.学好VHDL的关键是充分理解VHDL语句和硬件电路的关系.编写VHDL,就是在描述一个电路,我们写完一段程序后, ...
- JavaScript学习代码整理(二)--函数
//JavaScript函数 //简单的求和函数 function sum(a,b) { return a + b; } //函数可以存储在变量中,也可以通过变量调用函数 x = sum(a,b); ...
- 二维卷积c代码
二维卷积c代码 二维信号的卷积原理请参考另外一篇文章:http://blog.csdn.net/carson2005/article/details/43702241 这里直接给出参考代码: void ...
- Emily姨妈家的猫
按书上的样例,慢慢理解. 其实,JAVASCRIPT也应该可以写出正规点的,封装性好的代码. <html> <body> <script type="text/ ...
- android 获取 imei号码 及相关信息
android 获取 imei号码 参考:http://www.cnblogs.com/luxiaofeng54/archive/2011/03/01/1968063.html 核心代码: Imei ...