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 }

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

BZOJ1665 Usaco2006 Open The Climbing Wall的相关文章

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

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

bzoj1665:攀岩

1665: [Usaco2006 Open]The Climbing Wall 攀岩 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 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

[BZOJ1717][Usaco2006 Dec]Milk Patterns 产奶的模式

1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 1297  Solved: 705 [Submit][Status][Discuss] Description 农夫John发现他的奶牛产奶的质量一直在变动.经过细致的调查,他发现:虽然他不能预见明天产奶的质量,但连续的若干天的质量有很多重叠.我们称之为一个"模式". John的牛奶按质量可以被赋予一个0到100

70. Climbing Stairs

1. 问题描述 You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Tags:Dynamic Programming 2. 解题思路 简单分析之: f(1) = 1; f(2) = 2; f(3) = f(2) + f(1)

HDOJ 1348 Wall 凸包

Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4001    Accepted Submission(s): 1131 Problem Description Once upon a time there was a greedy King who ordered his chief Architect to build a

leetcode - Climbing Stairs

You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? //第一种解法 class Solution { public: int climbStairs(int n) { int ans[100] = {1,2}; for

hdu 1348 Wall(凸包模板题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3386    Accepted Submission(s): 968 Problem Description Once upon a time there was a gre

BZOJ1725: [Usaco2006 Nov]Corn Fields牧场的安排

1725: [Usaco2006 Nov]Corn Fields牧场的安排 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 400  Solved: 290[Submit][Status] Description Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行(1<=M<=12; 1<=N<=12),每一格都是一块正方形的土地.FJ打算在牧场上的某几格土地里种上美味的草,供他的奶牛们享用.遗憾的是,有些土地相当的贫