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 ...
随机推荐
- ASP.NET开发实战——(四)ASP.NET MVC是如何运行的?它的生命周期是什么?
前面的文章我们使用ASP.NET MVC创建了个博客应用,那么它是如何工作的呢?我们都知道ASP.NET的程序需要部署到IIS上才能够通过浏览器来访问,那么IIS与ASP.NET MVC程序之间又是如 ...
- [LeetCode] 827. Making A Large Island 建造一个巨大岛屿
In a 2D grid of 0s and 1s, we change at most one 0 to a 1. After, what is the size of the largest is ...
- [LeetCode] 159. Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串
Given a string s , find the length of the longest substring t that contains at most 2 distinct char ...
- [转]Visual Studio 2017各版本安装包离线下载、安装全解析
Visual Studio 2017各版本安装包离线下载.安装全解析 2017-3-10 11:15:03来源:IT之家作者:寂靜·櫻花雨责编:晨风评论:165 感谢IT之家网友 寂靜·櫻花雨的投 ...
- xunit测试无法找到testhost或没有可用测试的问题解决方法
xunit进行测试,需要安装如下几个包: Microsoft.TestPlatform.TestHost Microsoft.NET.Test.Sdk xunit.runner.visualstudi ...
- scala中分组的算子的用法
val rdd= sc.parallelize(List(("tom",1),("jerry",3),("kitty",2),(" ...
- WPF Adorner 弹出式工具栏 例子
源于MSDN 一个问题. 问:如何做出类似word的文字选中后工具栏弹出和动画效果. 我用的是adorner,其实用popup也是可以的. 效果图: 中间黑色部分代表真正的工具栏. xaml代码: & ...
- 前端学习:CSS的学习总结(图解)
前端学习:CSS的学习总结(图解) CSS代码笔记 CSS简介 css的引入方式和书写规范 CSS选择器 CSS属性 CSS盒子模型 CSS的定位
- Linux 笔记 - 第二十三章 MySQL 主从复制配置
一.前言 MySQL Replication,也被称为主从复制.AB 复制.简单来说就是 A 和 B 两台服务器做主从后,在 A 服务器上写入数据,B 服务器上也会跟着写入输入,两者之间的数据是实时同 ...
- 聊聊 .net Core webAPi 的Get和POST 相关(1)
上篇文章,我们试着调用API,成功返回值,今天接下来看看代码是怎么构成的 [Route("api/[controller]")] [ApiController] public cl ...