BZOJ1665 Usaco2006 Open The Climbing Wall

Posted zhangenming

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BZOJ1665 Usaco2006 Open The Climbing Wall相关的知识,希望对你有一定的参考价值。

1665: [Usaco2006 Open]The Climbing Wall 攀岩

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 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 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

技术分享图片
 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 inline int read(){
 5     int x=0;int f=1;char ch=getchar();
 6     while(!isdigit(ch)) {if(ch==-) f=-1;ch=getchar();}
 7     while(isdigit(ch)) {x=x*10+ch-0;ch=getchar();}
 8     return x*f;
 9 }
10 const int MAXN=1e6+10;
11 struct node{
12     int y,next;
13 }e[MAXN];
14 struct hh{
15     int x,y;
16 }k[MAXN];
17 int linkk[MAXN],len=0,h,n,dis[MAXN],vis[MAXN];
18 typedef pair <int,int> pii;
19 priority_queue < pii,vector<pii>,greater<pii> > q;
20 inline void insert(int xx,int yy){
21     e[++len].y=yy;e[len].next=linkk[xx];linkk[xx]=len;
22 }
23 namespace zhangenming{
24     void dijsktra(){
25         q.push(make_pair(0,n+1));
26         memset(dis,127,sizeof(dis));
27         dis[n+1]=0;
28         while(!q.empty()){
29             int tn=q.top().second;q.pop();
30             if(vis[tn])  continue;vis[tn]=1;
31             for(int i=linkk[tn];i;i=e[i].next){
32                 if(dis[tn]+1<dis[e[i].y]){
33                     dis[e[i].y]=dis[tn]+1;
34                     q.push(make_pair(dis[e[i].y],e[i].y));
35                 }
36             }
37         }
38     }
39     void init(){
40         h=read();
41         n=read();
42         for(int i=1;i<=n;i++){
43             k[i].x=read();k[i].y=read();
44         }
45         for(int i=1;i<=n;i++){
46             for(int j=i+1;j<=n;j++){
47                 if((k[i].x-k[j].x)*(k[i].x-k[j].x)+(k[i].y-k[j].y)*(k[i].y-k[j].y)<=1000000) insert(i,j),insert(j,i);
48             }
49             if(k[i].y<=1000) insert(n+1,i);
50             if(k[i].y>=h-1000) insert(i,n+2);
51         }
52         dijsktra();
53         cout<<dis[n+2]-1<<endl;
54     }
55 }
56 int main(){
57     using namespace zhangenming;
58     init();
59     return 0;
60 }
View Code

 














以上是关于BZOJ1665 Usaco2006 Open The Climbing Wall的主要内容,如果未能解决你的问题,请参考以下文章

bzoj1663: [Usaco2006 Open]赶集

bzoj1664: [Usaco2006 Open]County Fair Events 参加节日庆祝

BZOJ1663: [Usaco2006 Open]赶集

BZOJ1727: [Usaco2006 Open]The Milk Queue 挤奶队列

bzoj 1688: [Usaco2005 Open]Disease Manangement 疾病管理

bzoj1725[Usaco2006 Nov]Corn Fields牧场的安排*