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.

Sample Input

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

Sample Output

3

如果能从石头i跳到石头j,那么i和j连一条无向边

新建一个源点0和汇点n+1, 所有高度小于等于1000的点全部和源点连一条无向边,所有高度大于等于H-1000的点全部和汇点连一条无向边,然后求0到n+1的最短路

#include<stdio.h>
#include<string.h>
#include<vector>
#include<queue>
using namespace std;
typedef struct
{int x;int y;
}Point;
Point s[10005];
vector<int> G[10005];
queue<int> q;
int bet[10005];
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[0].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] = 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;
}

bzoj 1665: [Usaco2006 Open]The Climbing Wall 攀岩(最短路)相关推荐

  1. 【BZOJ】1665: [Usaco2006 Open]The Climbing Wall 攀岩(spfa)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1665 这题只要注意到"所有的落脚点至少相距300"就可以大胆的暴力了. 对于每个 ...

  2. BZOJ1665 Usaco2006 Open The Climbing Wall

    1665: [Usaco2006 Open]The Climbing Wall 攀岩 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 407  Solve ...

  3. BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数(数位DP+恶心细节)

    BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数 Time Limit: 5 Sec  Memory Limit: 64 MB Description 正如你所知 ...

  4. BZOJ 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝( dp )

    先按时间排序( 开始结束都可以 ) , 然后 dp( i ) = max( dp( i ) , dp( j ) + 1 ) ( j < i && 节日 j 结束时间在节日 i 开 ...

  5. bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 -- Tarjan

    1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 Time Limit: 5 Sec  Memory Limit: 64 MB Description The N (2 & ...

  6. BZOJ 1724: [Usaco2006 Nov]Fence Repair 切割木板

    题目 1724: [Usaco2006 Nov]Fence Repair 切割木板 Time Limit: 5 Sec  Memory Limit: 64 MB Description Farmer ...

  7. 后缀数组2.0--Height数组(bzoj 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式)

    前置技能:后缀数组 height[i]:排名第i的后缀与排名第i-1的后缀的最长公共前缀,也就是sa[i]和sa[i-1]的最长公共前缀 h[i]:以第i个字符为起点的后缀与排名在它前1名的后缀的最长 ...

  8. bzoj 1726: [Usaco2006 Nov]Roadblocks第二短路(A*第k短路)

    1726: [Usaco2006 Nov]Roadblocks第二短路 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 1324  Solved: 627 ...

  9. bzoj 1659: [Usaco2006 Mar]Lights Out 关灯(IDA*)

    1659: [Usaco2006 Mar]Lights Out 关灯 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 298  Solved: 73 [S ...

最新文章

  1. Spring Boot项目部署到Heroku
  2. tf.control_dependencies()控制计算流图
  3. 北京/苏州内推 | 微软STCA搜索广告算法团队招聘NLP算法工程师
  4. JSON JsonArray和JsonObject学习资料
  5. java架构师之路:JAVA程序员必看的15本书的电子版下载地址
  6. pig连接oracle数据库,Pig安装讲解
  7. 《who Who Are You Working For》(你在为谁工作)
  8. 给小组新成员的一份信
  9. 人到中年生活不易,特别是工作压力很大
  10. MySQL的show profile(已过时)简介以及该功能在MySQL 5.7中performance_schema中的替代
  11. 2021牛客寒假算法基础集训营2,签到题FHIJ
  12. linux下分析prn文件,Linux文件的管理
  13. 亚马逊测评自养号IP重要性
  14. 密码学基础(数学理论)
  15. 微信小程序之评分页面
  16. 7-111 输出大写英文字母
  17. hdu 1849 Rabbit and Grass Nim博弈
  18. 【FCC】检查字符串结尾
  19. 那些牛逼互联网公司里技术团队的博客
  20. Linux(二十七):在Linux系统上安装Git

热门文章

  1. python自学行吗-有编程基础Python自学行吗?
  2. 苹果测试集了成语音识别和人脸识别的智能家居?
  3. 怎么二值化后找字_邓婕美肤团队:秋季皮肤出现问题后怎么办 找对护肤方法是关键_美肤吧...
  4. Vue动态设置Style属性
  5. pandas折线图x轴显示不全_python - 为什么在Geopandas中显示折线图时会忽略绘图顺序 - 堆栈内存溢出...
  6. vue(vue-cli+vue-router)+babel+webpack项目搭建入门(四)
  7. 算法笔记:二叉树的序列化和反序列化(剑指 Offer 37)
  8. 最简单的视频编码器:基于libx264(编码YUV为H.264)
  9. x264编码指南——码率控制
  10. 基于内容的图像检索系统(合集)