HDU 1548 A strange lift 题解
A strange lift
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 33697 Accepted Submission(s): 12038
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
//Author:LanceYu
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<fstream>
#include<iosfwd>
#include<sstream>
#include<fstream>
#include<cwchar>
#include<iomanip>
#include<ostream>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<ctime>
#include<algorithm>
#include<complex>
#include<cmath>
#include<valarray>
#include<bitset>
#include<iterator>
#define ll long long
using namespace std;
const double clf=1e-;
//const double e=2.718281828;
const double PI=3.141592653589793;
const int MMAX=;
//priority_queue<int>p;
//priority_queue<int,vector<int>,greater<int> >pq;
struct node
{
int x,step;
};
int n,start,last;
int dir[][],vis[];//dir分为两个方向,向上和向下
int bfs(int start,int last)
{
int i;
queue<node> q;
q.push(node{start,});
vis[start]=;
while(!q.empty())
{
node t=q.front();
q.pop();
if(t.x==last)
return t.step;
for(int i=;i<;i++)
{
int dx=t.x+dir[i][t.x];
if(dx>=&&dx<n&&!vis[dx])//一维深度搜索
{
vis[dx]=;
q.push(node{dx,t.step+});
}
}
}
return -;
}
int main()
{
int temp;
while(scanf("%d",&n)!=EOF)//这里输入要分开,因为输入为0时停止
{
if(n==)
return ;
scanf("%d%d",&start,&last);
memset(vis,,sizeof(vis));
for(int i=;i<n;i++)//每一层的数据录入,包括两个方向
{
scanf("%d",&temp);
dir[][i]=temp;
dir[][i]=-temp;
}
int ans=bfs(start-,last-);//注意此处要-1,受到数组的限制和影响
printf("%d\n",ans);
}
return ;
}
2018-11-16 01:05:38 Author:LanceYu
HDU 1548 A strange lift 题解的更多相关文章
- hdu 1548 A strange lift
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1548 A strange lift Description There is a strange li ...
- 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 ...
- HDU 1548 A strange lift (Dijkstra)
A strange lift http://acm.hdu.edu.cn/showproblem.php?pid=1548 Problem Description There is a strange ...
- 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 (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 搜索
A strange lift Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- hdu 1548 A strange lift (bfs)
A strange lift Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Hdoj 1548.A strange lift 题解
Problem Description There is a strange lift.The lift can stop can at every floor as you want, and th ...
- 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 ...
随机推荐
- Xamarin.Forms移动开发系列3:项目剖析
摘要 本文主要进行Xamarin.Forms应用程序剖析. 前言 本文介绍Xamarin.Forms应用程序剖析. 由于本系列重点研究对象为Xamarin.Forms,所以对Xamarin.Andro ...
- MySQL实战45讲学习笔记:第二十讲
一.引子 在上一篇文章最后,我给你留了一个关于加锁规则的问题.今天,我们就从这个问题说起吧. 为了便于说明问题,这一篇文章,我们就先使用一个小一点儿的表.建表和初始化语句如下(为了便于本期的例子说明, ...
- windows上MongoDB远程访问配置
今天用另一台机器上的MongoDB,但是使用本地连接时,没问题 换成IP地址时,出现 解决的方法,修改配置文件 systemLog: destination: file path: d:/Mongod ...
- 为某金融企业开发团队分享DevOps Server流水线使用经验
http://www.cnblogs.com/danzhang/ DevOps MVP 张洪君
- com.sun.jdi.InvocationException occurred invoking
调试时候出现com.sun.jdi.InvocationException occurred invoking method 原因:因为hibernate的延迟加载引起 修改:修改hbm映射文件的对象 ...
- SQLserver 存储过程游标使用
ALTER PROCEDURE [dbo].[p_DeleteStretchData] ) , ) AS BEGIN ) ) declare @stretch_cursor cursor -- 声明游 ...
- 修改Yarn的全局安装和缓存位置
在CMD命令行中执行 #1.改变 yarn 全局安装位置 yarn config set global-folder "你的磁盘路径" #2.然后你会在你的用户目录找到 `.yar ...
- sort和sorted
sort 与 sorted 区别: sort 是应用在 list 上的方法,sorted 可以对所有可迭代的对象进行排序操作. list 的 sort 方法返回的是对已经存在的列表进行操作,而内建函数 ...
- CentOS7 安装nginx-1.14.0
nginx源码包:http://nginx.org/en/download.html 1.安装gcc gcc是用来编译下载下来的nginx源码 yum install gcc-c++ 2.安装pcre ...
- 四、Hexo静态博客绑定域名及域名解析
示例: http://zsy.xyz/ 域名准备 购买域名及实名认证不再赘述,可通过阿里云.腾讯云等平台自行购买域名. 域名解析 进入解析界面 添加记录 选择主机记录,根据提示自行选择 记录类型选 ...