# bzoj 1665: [Usaco2006 Open]The Climbing Wall 攀岩（最短路）

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

Time Limit: 5 Sec   Memory Limit: 64 MB
Submit: 378   Solved: 201
[ 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.

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

## Sample Output

3

#include<stdio.h>
#include<string.h>
#include<vector>
#include<queue>
using namespace std;
typedef struct
{
int x;
int y;
}Point;
Point s;
vector<int> G;
queue<int> q;
int bet;
int main(void)
{
int h, n, i, j, x, y;
scanf("%d%d", &h, &n);
for(i=1;i<=n;i++)
scanf("%d%d", &s[i].x, &s[i].y);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(i!=j && (s[i].x-s[j].x)*(s[i].x-s[j].x)+(s[i].y-s[j].y)*(s[i].y-s[j].y)<=1000000)
{
G[i].push_back(j);
G[j].push_back(i);
}
}
}
for(i=1;i<=n;i++)
{
if(s[i].y<=1000)
G.push_back(i);
if(s[i].y+1000>=h)
G[i].push_back(n+1);
}
q.push(0);
memset(bet, 62, sizeof(bet));
bet = 0;
while(q.empty()==0)
{
x = q.front();
q.pop();
for(i=0;i<G[x].size();i++)
{
y = G[x][i];
if(bet[x]+1<bet[y])
{
bet[y] = bet[x]+1;
q.push(y);
}
}
}
printf("%d\n", bet[n+1]-1);
return 0;
}

02-04 83                                                                          09-14 33
09-07 70
08-23 2783
11-25 6456
09-28
05-24 6万+
06-16 1万+
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客