HDU 1548 A strange lift(BFS)
Problem Description
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"?
Input
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.
Output
Sample Input
5 1 5
3 3 1 2 5
0
Sample Output
3
/*
Sample Input
5 1 5
3 3 1 2 5
0
Sample Output
3
*/
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
int n,b;//n是层数,b是终点
int floor[];
bool vis[];
struct node
{
int f,step;
}a;//a是起点
int bfs()
{
queue<node>Q;
Q.push(a);
node cur,next;
while(!Q.empty())
{
cur=Q.front();
Q.pop();
vis[cur.f]=true;
if(cur.f==b)
return cur.step;//bfs广搜直接得出的就是最优解
for(int i=-;i<=;i+=)//上下方向
{
next.f=cur.f+i*(-)*floor[cur.f];
next.step=cur.step+;
if(next.f>=&&next.f<=n&&!vis[next.f])
{
Q.push(next);//bfs不需要回溯
}
}
}
return -;
}
int main()
{
while(cin>>n&&n)
{
cin>>a.f>>b;
a.step=;
for(int i=;i<=n;i++)
{
cin>>floor[i];
}
memset(vis,false,sizeof(vis));
cout<<bfs()<<endl;
}
return ;
}
HDU 1548 A strange lift(BFS)的更多相关文章
- 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 ...
- HDU 1548 A strange lift (Dijkstra)
https://vjudge.net/problem/HDU-1548 题意: 电梯每层有一个不同的数字,例如第n层有个数字k,那么这一层只能上k层或下k层,但是不能低于一层或高于n层,给定起点与终点 ...
- HDU 1548 A strange lift (广搜)
题目链接 Problem Description There is a strange lift.The lift can stop can at every floor as you want, a ...
- HDU 1548 A strange lift (最短路/Dijkstra)
题目链接: 传送门 A strange lift Time Limit: 1000MS Memory Limit: 32768 K Description There is a strange ...
- hdu 1548 A strange lift(迪杰斯特拉,邻接表)
A strange lift Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1548 A strange lift(dij+邻接矩阵)
( ̄▽ ̄)" //dijkstra算法, //只是有效边(即能从i楼到j楼)的边权都为1(代表次数1): //关于能否到达目标楼层b,只需判断最终lowtime[b]是否等于INF即可. # ...
- HDU 1548 A strange lift【BFS】
题意:给出一个电梯,给出它的层数f,给出起点s,终点g,以及在每一层能够上或者下w[i]层,问至少需要按多少次按钮到达终点. 和POJ catch that cow一样,直接用了那一题的代码,发现一直 ...
- HDU.2612 Find a way (BFS)
HDU.2612 Find a way (BFS) 题意分析 圣诞节要到了,坤神和瑞瑞这对基佬想一起去召唤师大峡谷开开车.百度地图一下,发现周围的召唤师大峡谷还不少,这对基佬纠结着,该去哪一个...坤 ...
- 杭电 1548 A strange lift(广搜)
http://acm.hdu.edu.cn/showproblem.php?pid=1548 A strange lift Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- python学习站点
1.python 外部扩展网址 http://www.lfd.uci.edu/~gohlke/pythonlibs Python Extension Packages 2.web2py学习 http: ...
- Python matplot画柱状图(一)
图的存在,让数据变得形象化.无论多么复杂的东西,都是简单的组合. import matplotlib.pyplot as plt import numpy as np dict = {'A': 40, ...
- python 二进制数相加
def add_binary_nums(x,y): max_len = max(len(x), len(y)) x = x.zfill(max_len) y = y.zfill(max_len) re ...
- Python requests介绍之接口介绍
Python requests介绍 引用官网介绍 Requests 唯一的一个非转基因的 Python HTTP 库,人类可以安全享用. Requests 允许你发送纯天然,植物饲养的 HTTP/1. ...
- php--------返回404状态
php header()返回404状态代码的两种方式 //方式一 header('HTTP/1.1 404 Not Found');exit('404') //方式二 header("sta ...
- qxx 项目总结
一.账号池功能 1. 右边注释添加格式 private $client; // Jyeoo的接口 2. 将一些配置放到某个配置文件中,然后通过加载配置环境,来获取相关的变量 app()->con ...
- OAF多语言的实现
在之前的文章中转载了一篇关于多语言实现的文章. OAF中多语言的实现(转) 现在我来讲讲另外一种情况. 在建立工程项目没有特别选择语言,所以所有的PG或RN页面都是英文的,在页面原文件中可看到如下内容 ...
- ora2pg安装及卸载
--ora2pg安装 tar xzf ora2pg-10.x.tar.gz or tar xjf ora2pg-10.x.tar.bz2 cd ora2pg-10.x/ perl Makefile. ...
- POJ 2263 最短路Floyd_warshall算法
灰常开心的用Floyd变形写出来了.额.对米来说还是牺牲了一定的脑细胞的.然而.我发现.大牛们还可以神奇的用Kruskal求最大生成树的最小权值来写.也可以用Dijkatra变形来写.T_T....5 ...
- SQL Server SqlCacheDependency 缓存依赖
SQL server数据缓存依赖有两种实现模式,轮询模式,通知模式. 1 轮询模式实现步骤 此模式需要SQL SERVER 7.0/2000/2005版本以上版本都支持 主要包含以下几步: 1. ...