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 ...
随机推荐
- A1033 To Fill or Not to Fill (25 分)
一.技术总结 是贪心算法的题目,题目主要考虑的问题有几个,是否会在第一个加油站的最近距离大于0,如果是这样那么直接输出答案,因为初始油箱没有汽油: 第二个是如何选定加油站,如果在可到达距离范围类,我们 ...
- [LeetCode] 663. Equal Tree Partition 划分等价树
Given a binary tree with n nodes, your task is to check if it's possible to partition the tree to tw ...
- RDS for MySQL权限问题(错误代码:1227,1725)
https://help.aliyun.com/knowledge_detail/41701.html 错误信息 [Err] 1227 - Access denied; you need (at ...
- Econ 493 A1 - Fall 2019
Econ 493 A1 - Fall 2019Homework 4Assignment InformationThis assignment is due on Monday November 18 ...
- Java中调用存储过程
dao层: import java.util.Map; public interface AppGthdDao { public String gthd(Map map); } mapper层 < ...
- Mocha测试框架,保证代码质量
mocha mocha是JavaScript的一种单元测试框架,既可以在浏览器环境下运行,也可以在Node.js环境下运行. 使用mocha,我们就只需要专注于编写单元测试本身,然后,让mocha去自 ...
- Extra:Cg Math Functions
常用Cg函数 数学函数 abs(x):绝对值 // float类型的实现 float abs(float x) { return max(-a, a); } sin(x):正弦,输入为弧度 // fl ...
- [转帖]超能课堂(210) 笔记本中常说的PL1、PL2到底如何影响CPU性能?
超能课堂(210)笔记本中常说的PL1.PL2到底如何影响CPU性能? https://www.expreview.com/71943.html 本文约 4070 字,需 7 分钟阅读 (切换至标准版 ...
- 宽字符与Unicode (c语言 汉语字符串长度)
在C语言中,我们使用char来定义字符,占用一个字节,最多只能表示128个字符,也就是ASCII码中的字符.计算机起源于美国,char 可以表示所有的英文字符,在以英语为母语的国家完全没有问题. 但是 ...
- CMake方式编译
[1]CMake基础 CMake是一种跨平台编译工具 CMake主要是编写CMakeLists.txt文件 通过CMake命令将CMakeLists.txt文件转化为make所需的Makefile文件 ...