BZOJ1665 : [Usaco2006 Open]The Climbing Wall 攀岩
直接BFS貌似复杂度飞起来了,于是我们用k-d tree优化找点的过程即可。时间复杂度$O(n\sqrt{n})$。
#include<cstdio>
#include<algorithm>
const int N=10010,H=1000,R=1000000;
int n,m,i,root,cmp_d,h=1,t,q[N],f[N],mx,my,mz,ans;
inline void add(int x,int y){if(!f[x])f[q[++t]=x]=y;}
struct node{int d[2],l,r,Max[2],Min[2];}T[N];
inline bool cmp(node a,node b){
return (a.d[cmp_d]<b.d[cmp_d])||((a.d[cmp_d]==b.d[cmp_d])&&(a.d[!cmp_d]<b.d[!cmp_d]));
}
inline void umax(int&a,int b){if(a<b)a=b;}
inline void umin(int&a,int b){if(a>b)a=b;}
inline void up(int x){
if(T[x].l){
umax(T[x].Max[0],T[T[x].l].Max[0]);
umin(T[x].Min[0],T[T[x].l].Min[0]);
umax(T[x].Max[1],T[T[x].l].Max[1]);
umin(T[x].Min[1],T[T[x].l].Min[1]);
}
if(T[x].r){
umax(T[x].Max[0],T[T[x].r].Max[0]);
umin(T[x].Min[0],T[T[x].r].Min[0]);
umax(T[x].Max[1],T[T[x].r].Max[1]);
umin(T[x].Min[1],T[T[x].r].Min[1]);
}
}
int build(int l,int r,int D){
int mid=(l+r)>>1;
cmp_d=D,std::nth_element(T+l+1,T+mid+1,T+r+1,cmp);
T[mid].Max[0]=T[mid].Min[0]=T[mid].d[0];
T[mid].Max[1]=T[mid].Min[1]=T[mid].d[1];
if(l!=mid)T[mid].l=build(l,mid-1,!D);
if(r!=mid)T[mid].r=build(mid+1,r,!D);
return up(mid),mid;
}
inline int sqr(int x){return x*x;}
inline int max(int a,int b){return a>b?a:b;}
inline void ask(int x){
if(!x)return;
if(sqr(max(max(mx-T[x].Max[0],T[x].Min[0]-mx),0))+sqr(max(max(my-T[x].Max[1],T[x].Min[1]-my),0))>R)return;
if(sqr(T[x].d[0]-mx)+sqr(T[x].d[1]-my)<=R)add(x,mz);
ask(T[x].l);ask(T[x].r);
}
inline void read(int&a){char c;while(!(((c=getchar())>='0')&&(c<='9')));a=c-'0';while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';}
int main(){
for(read(m),read(n),i=1;i<=n;i++)read(T[i].d[0]),read(T[i].d[1]);
root=build(1,n,0);
for(i=1;i<=n;i++)if(T[i].d[1]<=H)add(i,1);
while(h<=t)mx=T[i=q[h++]].d[0],my=T[i].d[1],mz=f[i]+1,ask(root);
for(ans=n,i=1;i<=n;i++)if(f[i]&&T[i].d[1]+H>=m&&ans>f[i])ans=f[i];
return printf("%d",ans),0;
}
BZOJ1665 : [Usaco2006 Open]The Climbing Wall 攀岩的更多相关文章
- BZOJ 1665: [Usaco2006 Open]The Climbing Wall 攀岩
题目 1665: [Usaco2006 Open]The Climbing Wall 攀岩 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 197 Sol ...
- 【BZOJ】1665: [Usaco2006 Open]The Climbing Wall 攀岩(spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=1665 这题只要注意到“所有的落脚点至少相距300”就可以大胆的暴力了. 对于每个点,我们枚举比他的x ...
- [Usaco2006 Open]The Climbing Wall 攀岩
Description One of the most popular attractions at the county fair is the climbing wall. Bessie want ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- usaco silver
大神们都在刷usaco,我也来水一水 1606: [Usaco2008 Dec]Hay For Sale 购买干草 裸背包 1607: [Usaco2008 Dec]Patting Heads 轻 ...
- BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 [后缀数组]
1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1017 Solved: ...
- [poj1113][Wall] (水平序+graham算法 求凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
- [LeetCode] Climbing Stairs 爬梯子问题
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- gcc -Wall -pedantic -ansi(转载)
转载自R-G-Y-CQ的新浪博客 -Wall显示所有的警告信息 -Wall选项可以打开所有类型的语法警告,以便于确定程序源代码是否是正确的,并且尽可能实现可移植性. 对Linux开发人员来讲,GCC给 ...
随机推荐
- Tooltip jqueryui
(文章是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) http://jqueryui.com/tooltip/ <meta charset=&quo ...
- git clone报错
(文章是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) Could not chdir to home directory /home/wangzheng: ...
- vimcommandfilepatchcmdfold VIM技巧之分隔窗口 一级精华
VIM技巧之分隔窗口 分类: 技术2010-07-08 09:57 754人阅读 评论(1) 收藏 举报 同时显示两个不同的文件, 或者同时查看同一个文件的两个不同位置, 或者是同步显示两个文件的 ...
- [POJ1003]Hangover
[POJ1003]Hangover 试题描述 How far can you make a stack of cards overhang a table? If you have one card, ...
- 《ASP.NET MVC4 WEB编程》学习笔记------.net mvc实现原理ActionResult/View
ActionResult ActionResult是Action的返回结果.ActionResult 有多个派生类,每个子类功能均不同,并不是所有的子类都需要返回视图View,有些直接返回流,有些返回 ...
- debian下mysql主从配置
1.确保master/slave只有一份/etc/mysql/my.cnf , 不要在其他地方再有my.cnf (如/etc/my.cnf /usr/local之类) 2.master配置: 在[m ...
- spring mvc form表单提交乱码
spring mvc form表单submit直接提交出现乱码.导致乱码一般是服务器端和页面之间编码不一致造成的.根据这一思路可以依次可以有以下方案. 1.jsp页面设置编码 <%@ page ...
- c++标准库中几个常见的数据结构的区别和应用规则
转载自http://www.lifecrunch.biz/archives/202 vector和built-in数组类似,它拥有一段连续的内存空间,并且起始地址不变,因此它能非常好的支持随即存取,即 ...
- php中重写和final关键字的使用
为什么把重写和final放在一起,原因就是一条:final的意思是不可更改的,也就是说final定义的东西是不可改变的,下面具体来说一下. 来看一段简单的代码: class BaseClass { f ...
- 19.python笔记之Rabbitmq
RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统.他遵循Mozilla Public License开源协议. MQ全称为Message Queue, 消息队列(MQ)是一种应用程序 ...