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 ...
随机推荐
- django -- admin里的配置
前戏 Django给我们提供了一个后台管理系统,方便我们进行数据表的管理 创建超级用户 python manage.py createsuperuser 配置 默认我们登录到后台不显示任何一张表,如果 ...
- Linux性能优化实战学习笔记:第四讲
一.怎么查看系统上下文切换情况 通过前面学习我么你知道,过多的上下文切换,会把CPU时间消耗在寄存器.内核栈以及虚拟内存等数据的保存和回复上,缩短进程真正运行的时间,成了系统性能大幅下降的一个元凶 既 ...
- [LeetCode] 727. Minimum Window Subsequence 最小窗口序列
Given strings S and T, find the minimum (contiguous) substring W of S, so that T is a subsequence of ...
- [LeetCode] 394. Decode String 解码字符串
Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where ...
- c语言编译器一个不会报错的陷阱
1, 由于数字1和小写字母L(l)长得特别像,特别是VS默认字体里的,所以 double a; scanf("%1f",&a); double b; scanf(" ...
- oracle--JOB任务
1.创建一张测试表 -- Create table create table A8 ( a1 VARCHAR2(500) ) tablespace TT1 pctfree 10 initrans 1 ...
- java语言规范
一.标志符 命名规则: 标识符由26个英文字符大小写(a~zA~Z).数字(0~9).下划线(_)和美元符号($)组成. 不能以数字开头,不能是关键字 严格区分大小写 标识符的可以为任意长度 命名规范 ...
- [Powershell]发布基于.NET Framework的WebAPI和Job控制台程序项目
获取要发布的定时计划任务. 禁用和停止定时计划任务. 批量强制结束Job进程. 打印定时计划任务状态. 备份项目文件夹. 发布项目文件夹. 删除部署包. 启用定时计划任务. <# .NOTES ...
- vins_fusion学习笔记
Vins-Fusion源码:https://github.com/HKUST-Aerial-Robotics/VINS-Fusion 摘要 应项目需要,侧重学习stereo+gps融合 转载几篇写的比 ...
- 发送邮件报错javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed
关于使用javaMail发送邮件报错:javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multip ...