HDU1548- A strange lift (BFS入门)
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1548
A Strrange lift
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25550 Accepted Submission(s): 9189
Here comes the problem: when you are on floor A,and you want to go to floor B,how many times at least he has to press the button "UP" or "DOWN"?
The first line contains three integers N ,A,B( 1 <= N,A,B <= 200) which describe above,The second line consist N integers k1,k2,....kn.
A single 0 indicate the end of the input.
3 3 1 2 5
0
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
int v[],t[];
int main()
{
int n,a,b,i;
while(scanf("%d",&n)!=EOF)
{
if(n==)
break;
scanf("%d%d",&a,&b);
memset(t,,sizeof(t));
memset(v,,sizeof(v));
for(i=;i<=n;i++)
{
scanf("%d",&t[i]);
}
queue<int > q;
q.push(a);
v[a]=;
while(!q.empty())
{
int ll=q.front(),r=ll-t[ll],l=ll+t[ll];
q.pop();
if(l<=n&&!v[l])
{
q.push(l);
v[l]=v[ll]+;
}
if(r>=&&!v[r])
{
q.push(r);
v[r]=v[ll]+;
}
if(l==b||r==b)
break;
}
printf("%d\n",v[b]-);
}
return ; }
HDU1548- A strange lift (BFS入门)的更多相关文章
- hdu1548 A strange lift(bfs 或Dijkstra最短路径)
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #d ...
- HDU-1548 A strange lift(单源最短路 或 BFS)
Problem Description There is a strange lift.The lift can stop can at every floor as you want, and th ...
- HDU1548——A strange lift(最短路径:dijkstra算法)
A strange lift DescriptionThere is a strange lift.The lift can stop can at every floor as you want, ...
- hdu 1548 A strange lift (bfs)
A strange lift Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDU1548:A strange lift
A strange lift Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- Hdu1548 A strange lift 2017-01-17 10:34 35人阅读 评论(0) 收藏
A strange lift Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- HDU 1548 A strange lift (bfs / 最短路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1548 A strange lift Time Limit: 2000/1000 MS (Java/Ot ...
- bfs A strange lift
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1548 There is a strange lift.The lift can stop can at e ...
- hdu 1548 A strange lift 宽搜bfs+优先队列
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1548 There is a strange lift.The lift can stop can at ...
随机推荐
- Convert java.lang.String to oracle.jbo.domain.Date
https://www.techartifact.com/blogs/2013/09/converting-java-lang-string-to-oracle-jbo-domain-date.htm ...
- [LightOJ 1265] Island of Survival
Island of Survival You are in a reality show, and the show is way too real that they threw into an i ...
- iOS 时间校准解决方案
背景 在 iOS 开发中,凡是用到系统时间的,都要考虑一个问题:对时.有些业务是无需对时,或可以以用户时间为准的,比如动画用到的时间.一些日程类应用等.但电商相关的业务大都不能直接使用设备上的时间,而 ...
- DBCC - Undocumented commands
These commands may affect system performance and/or force table-level locks.There is no guarantee th ...
- npm使用国内淘宝镜像的方法
一.通过命令配置 1. 命令 npm config set registry https://registry.npm.taobao.org 2. 验证命令 npm config get regist ...
- 网页定位点击事件js响应函数教程(Chrome)
一.背景说明 在前端页面调试或者渗透测试(尤其是XSS)时,我们经常想定位js函数位置:比如点击了某个位置弹出了一个对话框,这是哪个文件的哪个js函数在响应. 本文以Chrome浏览器定位点击事件响应 ...
- SpringBoot主程序类,主入口类
主程序类,主入口类 /** * @SpringBootApplication 来标注一个主程序类,说明这是一个Spring Boot应用 */ @SpringBootApplication publi ...
- npm 安装nodesass 或者包含nodesass的脚手架工具报错问题
由于最近vue转angular 但是angular版本太多了,好多项目是angularv4 有的是v5 近日angular又发布了v6,依赖的东西好多不一样,结果npm install 时候,总是出现 ...
- while循环以及格式化输出总结
while循环: while 无限循环 count = 1 sum = 0 while True: sum = sum + count count = count + 1 if count == 10 ...
- oo作业总结(四)
测试与正确性论证 测试是通过构造一系列测试数据,通过对比程序的实际运行结果和预期输出结果来判断程序是否有bug的一种手段.同时,在测试的时候是默认看不到程序的具体实现的,即进行黑盒测试,例如每次OO作 ...