A strange lift_BFS
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
【题意】给出n层,要从s到t,给出每层只能下或者上a[i],问至少经过多少次才能从s到t
【思路】经典BFS
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
const int N=;
int a[N];
int vis[N];
int n,s,t;
struct node
{
int x;
int step;
};
bool go(int x)
{
if(x<=||x>n) return false;
return true;
}
int bfs()
{
node now,next;
queue<node>qu;
now.x=s;
now.step=;
qu.push(now);
while(!qu.empty())
{
now=qu.front();
qu.pop();
if(now.x==t)
return now.step;
for(int i=-;i<=;i+=)
{
next=now;
next.x+=a[next.x]*i;
if(go(next.x)&&vis[next.x]==)
{
vis[next.x]=;
next.step++;
qu.push(next); }
}
}
return -;
}
int main()
{
while(~scanf("%d",&n),n)
{
scanf("%d%d",&s,&t);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
memset(vis,,sizeof(vis));
int ans=bfs();
printf("%d\n",ans);
}
return ;
}
A strange lift_BFS的更多相关文章
- timus 1175. Strange Sequence 解题报告
1.题目描述: 1175. Strange Sequence Time limit: 1.0 secondMemory limit: 2 MB You have been asked to disco ...
- CF719C. Efim and Strange Grade[DP]
C. Efim and Strange Grade time limit per test 1 second memory limit per test 256 megabytes input sta ...
- HDU 1548 A strange lift (最短路/Dijkstra)
题目链接: 传送门 A strange lift Time Limit: 1000MS Memory Limit: 32768 K Description There is a strange ...
- ACM : HDU 2899 Strange fuction 解题报告 -二分、三分
Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- POJ 2891 Strange Way to Express Integers(拓展欧几里得)
Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express ...
- 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 ...
- poj 2891 Strange Way to Express Integers (非互质的中国剩余定理)
Strange Way to Express Integers Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 9472 ...
- A strange lift
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- strange error encountered today in ROS
I reinstalled my ubuntu system and also ROS. I tested slam_karto package when some strange error cam ...
随机推荐
- easyui dialog 扩展load
$.extend($.fn.panel.methods, { showMask: function(jq, msg){ return jq.each(function(){ var pal = $(t ...
- 我的android学习经历34
用类对象作为ArrayAdapter绑定的基本数据类型(和SimpleAdater效果类似) 一般ArrayAdapter绑定的基本数据类型是String,接下来介绍一下类对象作为基本数据类型: 首先 ...
- 第十四天 jni 的使用
1. ndk 环境 2.jni hello 程序. 3.javah 生成头文件. 4.java 和c 之间数据传递. 5.C语言回调java 代码 通过反射.得到字节码,得到方法...
- ubuntu删除软件命令
第一步,apt-get remove xxx :就是卸载xxx 或者 apt-get remove --purge xxx :卸载xxx并清除配置. 这两条命令对于依赖则是不管的.因为别的软件可 ...
- iOS开发数据库篇—SQLite简单介绍
iOS开发数据库篇—SQLite简单介绍 一.离线缓存 在项目开发中,通常都需要对数据进行离线缓存的处理,如新闻数据的离线缓存等. 说明:离线缓存一般都是把数据保存到项目的沙盒中.有以下几种方式 (1 ...
- 一步一步学习underscore的封装和扩展方式
前言 underscore虽然有点过时,这些年要慢慢被Lodash给淘汰或合并. 但通过看它的源码,还是能学到一个库的封装和扩展方式. 第一步,不污染全局环境. ES5中的JS作用域是函数作用域. 函 ...
- 《BI那点儿事》META DATA(元数据)
关于数据仓库的数据,指在数据仓库建设过程中所产生的有关数据源定义,目标定义,转换规则等相关的关键数据.同时元数据还包含关于数据含义的商业信息,所有这些信息都应当妥善保存,并很好地管理.为数据仓库的发展 ...
- python 发送邮件实例
留言板回复作者邮件提醒 -----------2016-5-11 15:03:58-- source:python发送邮件实例
- Shell 语法之输入输出
Linux 使用文件描述符标识每个文件对象.文件描述符是一个非负整数,可以唯一地标识会话中打开的文件.每个进程中最多可以有9个打开文件的描述符. Linux 标准文件描述符 文件描述符 缩写 描述 0 ...
- windows下开启mysql远程访问
USE mysql;SELECT * FROM USER ; 直接修改user=root host=127.0.0.1为% FLUSH PRIVILEGES;