HDU1548- A strange lift (BFS入门)
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1548
A Strrange lift
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25550 Accepted Submission(s): 9189
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
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
int v[],t[];
int main()
{
int n,a,b,i;
while(scanf("%d",&n)!=EOF)
{
if(n==)
break;
scanf("%d%d",&a,&b);
memset(t,,sizeof(t));
memset(v,,sizeof(v));
for(i=;i<=n;i++)
{
scanf("%d",&t[i]);
}
queue<int > q;
q.push(a);
v[a]=;
while(!q.empty())
{
int ll=q.front(),r=ll-t[ll],l=ll+t[ll];
q.pop();
if(l<=n&&!v[l])
{
q.push(l);
v[l]=v[ll]+;
}
if(r>=&&!v[r])
{
q.push(r);
v[r]=v[ll]+;
}
if(l==b||r==b)
break;
}
printf("%d\n",v[b]-);
}
return ; }
HDU1548- A strange lift (BFS入门)的更多相关文章
- hdu1548 A strange lift(bfs 或Dijkstra最短路径)
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #d ...
- 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 ...
- HDU1548——A strange lift(最短路径:dijkstra算法)
A strange lift DescriptionThere is a strange lift.The lift can stop can at every floor as you want, ...
- hdu 1548 A strange lift (bfs)
A strange lift Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDU1548:A strange lift
A strange lift Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- Hdu1548 A strange lift 2017-01-17 10:34 35人阅读 评论(0) 收藏
A strange lift Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- 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 ...
- bfs A strange lift
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1548 There is a strange lift.The lift can stop can at e ...
- 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 ...
随机推荐
- Ubuntu下忘记MySQL root密码解决方法
1.忘了mysql密码,从网上找到的解决方案记录在这里. 编辑mysql的配置文件/etc/mysql/my.cnf,在[mysqld]段下加入一行“skip-grant-tables”. 2.重启服 ...
- SQL - 数据查询
数据查询是数据库的核心操作.SQL 提供了 select 语句进行数据查询,该语句的一般格式为: select [ ALL | distinct ] <目标列表达式> [ ,<目 ...
- 利用sqlldr从MySQL导出一张表数据到Oracle
根据业务需求,需要从MySQL库中同步一张表tap_application到Oracle中,下面是记录的导入过程. 1. 查看MySQL表结构 desc tap_application; +----- ...
- git报错fatal: I don't handle protocol 'https'处理
一.背景说明 今天使用在Cygwin中git clone时报fatal: I don't handle protocol 'https',如下: 以为是Cygwin实现的git有点问题没太在意,换去 ...
- js如何将选中图片文件转换成Base64字符串?
如何将input type="file"选中的文件转换成Base64的字符串呢? 1.首先了解一下为什么要把图片文件转换成Base64的字符串 在常规的web开发过程中,大部分上传 ...
- Spring boot异常统一处理方法:@ControllerAdvice注解的使用、全局异常捕获、自定义异常捕获
一.全局异常 1.首先创建异常处理包和类 2.使用@ControllerAdvice注解,全局捕获异常类,只要作用在@RequestMapping上,所有的异常都会被捕获 package com.ex ...
- linux下stat命令详解
在linux系统下,使用stat(显示inode信息)命令可以查看一个文件的某些信息,我们先来尝试一下. 简单的介绍一下stat命令显示出来的文件其他信息: - File:显示文件名 - Size: ...
- 逆袭之旅.DAY08东软实训.多态~
2018年7月4日
- laravel查找某个类拥有的方法:
1.在当前项目下,使用cmd窗口,输入: php artisan tinker 在输入: app('log') 显示出:Illuminate\Log\Writer 2.在phpstorm中按:shif ...
- 计算机基础part1
一:计算机的基本组成 1.计算机由输入单元.控制单元.算法逻辑单元.输出单元.存储单元,五大单元组成 二:概念篇 CPU:中央处理器,其内含有指令集(取码-解码-执行的过程) CPU同一时刻只能干一件 ...