bzoj1665:攀岩

1665: [Usaco2006 Open]The Climbing Wall 攀岩

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 229  Solved: 120
[Submit][Status][Discuss]

Description

One of the most popular attractions at the county fair is the climbing wall. Bessie wants to plan her trip up the wall in advance and needs your help. The wall is 30,000 millimeters wide and H (1001 <= H <= 30,000) millimeters high and has F (1 <= F <= 10,000) hoof-holds at unique X,Y coordinates expressed in millimeters. 0,0 is at the ground level on the left side of the wall. Hoof-holds are separated by at least 300 millimeters since no cow can maneuver them if they are spaced too close! Bessie knows there is at least one way up. Bessie, through techniques only she knows, uses successive single hoof-holds to climb the wall. She can only move from one hoof-hold to another if they are no more than one meter apart. She can, of course, move up, down, right, left or some combination of these in each move. Similarly, once she gets to a hoof-hold that is at least H-1000 millimeters above the ground, she can nimbly climb from there onto the platform atop the wall. Bessie can start at any X location that has a Y location <= 1000 millimeters. Given the height of the wall and the locations of the hoof-holds, determine the smallest number of hoof-holds Bessie should use to reach the top.

Bessie参加了爬墙比赛,比赛用的墙宽30000,高H(1001 <= H <= 30,000)。墙上有F(1 <= F <= 10,000)个不同的落脚点(X,Y)。 (0,0)在左下角的地面。所有的落脚点至少相距300。Bessie知道至少有一条路可以上去。 Bessie只能从一个落脚点爬到另一个距离不超过1000的落脚点,她可以向上下左右四个方向爬行。同样地,一旦她到达了一个高度 至少有H-1000的落脚点,她可以敏捷地爬到墙顶上。Bessie一开始可以在任意一个高度不超过1000的落脚点上。问Bessie至少攀爬多少次.这里两个点的距离都是欧几里得距离

Input

* Line 1: Two space-separated integers, H and F.

* Lines 2..F+1: Each line contains two space-separated integers (respectively X and Y) that describe a hoof-hold. X is the distance from the left edge of the climbing wall; Y is the distance from the ground.

Output

* Line 1: A single integer that is the smallest number of hoof-holds Bessie must use to reach the top of the climbing wall.

Sample Input

3000 5
600 800
1600 1800
100 1300
300 2100
1600 2300

INPUT DETAILS:

The wall is three meters high with 5 hoof-holds.

Sample Output

3

HINT

分别经过(600,800), (100,1300), (300,2100)

Source

Silver

不难吧,看懂题意后就不难想到是最短路了,然后跑一遍spfa或者dijkstra就好了,比较喜欢spfa比较容易写

a-------------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
const int nmax=3000005;
const int maxn=10005;
struct edge{
 int to,next;
};
edge e[nmax];
int x[maxn],y[maxn],head[maxn],d[maxn],v[maxn];
int n,cur=0,m;
double dis(int a,int b){
 return sqrt((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]));
}
void update(int x,int y){
 cur++;
 e[cur].next=head[x];
 e[cur].to=y;
 head[x]=cur;
 cur++;
 e[cur].next=head[y];
 e[cur].to=x;
 head[y]=cur;
}
void insert(){
 for(int i=1;i<n;i++){
  for(int j=i+1;j<=n;j++){
   if(dis(i,j)<=1000)
               update(i,j);
           
  }
 }
 for(int i=1;i<=n;i++){
  if(y[i]+1000>=m)
    update(i,n+1);
  if(y[i]<=1000)
    update(i,0);
 }
}
void spfa(){
 queue<int>q;
 q.push(0);
 memset(d,0x3f,sizeof(d));
 d[0]=0;
 v[0]=1;
 while(!q.empty()){
  int tmp=q.front();
  q.pop();
  v[tmp]=0;
  for(int j=head[tmp];j;j=e[j].next){
   int temp=e[j].to;
   if(d[temp]>d[tmp]+1){
    d[temp]=d[tmp]+1;
    if(!v[temp]){
     v[temp]=1;
     q.push(temp);
    }
   }
  }
 }
}
int main(){
 memset(head,0,sizeof(head));
 scanf("%d%d",&m,&n);
 for(int i=1;i<=n;i++){
  scanf("%d%d",&x[i],&y[i]);
 }
 insert();
 spfa();
 printf("%d\n",d[n+1]-1);
 return 0;
}

----------------------------------------------------------------------------------

时间: 2024-08-02 15:57:19

bzoj1665:攀岩的相关文章

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

BZOJ1665 Usaco2006 Open The Climbing Wall

1665: [Usaco2006 Open]The Climbing Wall 攀岩 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 407  Solved: 219[Submit][Status][Discuss] Description One of the most popular attractions at the county fair is the climbing wall. Bessie wants to plan her trip

bzoj:1665: [Usaco2006 Open]The Climbing Wall 攀岩

Description One of the most popular attractions at the county fair is the climbing wall. Bessie wants to plan her trip up the wall in advance and needs your help. The wall is 30,000 millimeters wide and H (1001 <= H <= 30,000) millimeters high and h

常被人忽略的顽疾之一!!!你不知道的冷知识

曾经有人在知乎上发出这样的问题:"我的指甲在过去的十年中已经拔过五次,为何新指甲仍然往肉里长,并且把指甲两侧的甲床破坏导致局部增生长出一大块肉粒,痛不欲生",随后附上一张惨不忍睹的大拇指照片,在这条问题下面,很多人回复自己也有同样的问题,并且对于治愈方法仍然处在未知状态.那么问题也便出现,为何会有这么多人出现指甲长进肉里,导致出现甲沟炎的情况.那么又应该怎么去治疗这种疾病呢,行健足科的足部专家做出了如下答复. 在了解指甲往肉里长的原因之前,先让我们来普及一下指甲到底是如何生长的.指甲相

贝--第一季

蠕虫,含有80%的蛋白质.而牛肉20% 波浪状的云朵    说明低气压马上就要来了 下雨了,声音会传的更远 从脚掌的按压成都还有爪子的排列看,也就1小时 如果入水的角度不好,就会像跳到地面而不是水面 就像这个"猫尾巴"  一种蒲草,很牛逼,里面的东西可以用来取火,还可以保暖  , 树茎可以做弓箭.  跟可以吃, 有淀粉 小水坑,高水位游上来 , 鱼也可以生吃? 叶子,  烤大约20分钟 鱼眼吐出来,说明烤好了 马尾巴的植物当牙刷 河水不能直接引用,即使看起来很干净 放了些浆果,加了些味

转载几篇别人写的皮肤类控件的技术文章

原连接:http://blog.sina.com.cn/s/blog_4c3538470100ezhu.html 实现控件的透明背景 很多情况下,我们需要控件 的背景是透明的,就是要求直接看到控件父窗口的背景颜色.背景位图,比如标签控件.单选Radio控件.复选Check控件,通常都要求在父窗口的背景上 进行绘制.然而要求控件的画布透明,这个技术在GDI的文档中没有看到Microsoft作任何说明,当然还是有别的办法. 其一: 如果程序支持桌面主题服务的话,则可调用主题服务的API来实现背景.我

MD、EVA、PU、PVC、TPU、DPU

RB.PU.PVC.TPU.TPR.TR, EVA .MD . DPU DPU是一种耐磨.韧性好的工程塑料,不比EVA或橡胶底或牛筋底差,但其质量比以上都轻,但易刺破不易攀岩 1.先说什么是MD:MODEL或PHYLON飞龙的统称 2.那么什么是PHYLON:(俗称飞龙)是一种做鞋底的材料一般制鞋用的中底, 用加热压缩的EVA发泡制成的混合物质.(属EVA二次高压成型品)特点质轻, 弹性及抗震性能好, 硬度是由发泡温度控制的. 3.那么什么是EVA:Ethylene Vinyl Acetate-

Qt下使用的静态链接库------ *.lib转化为mingw使用的.a格式的静态库

使用MinGW附带的工具reimp.exe,该工具一般在MinGW in目录下,其readme文档在MinGWdoc eimp目录下, 方法很简单,比如: C:CodeBlocksMinGWlibdx9>reimp d3d8.lib 就会生成一个“libd3d8.a”文件,这个文件就可以让基于MinGW的编译器链接使用了. 我用这个方法成功的把DirectX9c的.lib库转化成了.a库,并在CodeBlocks下编译成功了其生成的dx项目, 但是有三个.lib文件无法通过这个方法转换:DxEr

文化编码(Coding Culture)

英文原文:Coding Culture: How To Build Better Products by Building Stronger Teams 译/丛一 软件开发人员通常会付出大量的时间和精力在如何构建最好的产品上.我们常会纠结应该使用哪种Web框架,是用NoSQL数据库还是SQL数据库?不过,尽管这些问题十分重要,开发人员通常会忽视掉软件开发过程中与这些问题同样重要的一个方面——文化.本文将与读者分享在Atlanssian公司中如何保持健壮的创新和协作文化氛围的经验. 产品时刻都在发