「BZOJ1665」[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 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
600 800
1600 1800
100 1300
300 2100
1600 2300INPUT DETAILS:The wall is three meters high with 5 hoof-holds.
Sample Output
HINT
题解
发现题目中的点数不是很多,直接暴力
不然排序一下再建图什么的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<queue> #define pa pair<int,int> #define inf 100000000 #define ll long long using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int h,n,cnt; int x[10005],y[10005],d[10005]; int last[10005]; bool vis[10005]; struct data{int to,next;}e[2000005]; int dis(int a,int b) { return (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]); } void insert(int u,int v) { e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt; } void dijkstra() { priority_queue<pa,vector<pa>,greater<pa> >q; for(int i=0;i<=n+1;i++)d[i]=inf; d[0]=0;q.push(make_pair(0,0)); while(!q.empty()) { int now=q.top().second;q.pop(); if(vis[now])continue;vis[now]=1; for(int i=last[now];i;i=e[i].next) if(d[e[i].to]>d[now]+1) { d[e[i].to]=d[now]+1; q.push(make_pair(d[e[i].to],e[i].to)); } } } void build() { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) if(sqrt(dis(i,j))<=1000) insert(i,j); if(y[i]<=1000)insert(0,i); if(h-y[i]<=1000)insert(i,n+1); } } int main() { h=read();n=read(); for(int i=1;i<=n;i++) x[i]=read(),y[i]=read(); build(); dijkstra(); printf("%d",d[n+1]-1); return 0; } |