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 ...
随机推荐
- Mybatis异常There is no getter for property named 'XXX' in 'class java.lang.String'
1.当入参为 string类型时 (包括java.lang.String.) 我们使用#{xxx}引入参数.会抛异常There is no getter for property named 'XX ...
- Node.js + Express中间件详解
使用中间件 Express是一种路由和中间件Web框架,它具有自己的最小功能:Express应用程序本质上是一系列中间件函数调用. 中间件函数是可以访问请求对象 (req),响应对象(res)以及应用 ...
- H5新特性实现对class的增删改
直接撸代码 全靠死记硬背 没什么技术点 HTML部分 <!DOCTYPE html> <html lang="en"> <head> <m ...
- 从tcp的角度看,打开一个网页到底发生了什么
使用wireshark进行抓包分析:新建表达式过滤器,选择协议,字段,匹配方式,应用就能筛选出想要的数据包. 一个示例:(tcp.srcport == 1523 or tcp.dstport == 1 ...
- UNIX-like系统资源检查命令
系统资源主要是内存.磁盘.CPU三项,其中任一项资源用尽都会造成系统崩溃. 系统 内存 磁盘空间 磁盘io CPU Linux free -g df -h top AIX svmon -G/vms ...
- 转:Linux环境变量设置方法总结 PATH、LD_LIBRARY_PATH
转: https://www.linuxidc.com/Linux/2017-03/142338.htm 文章写比较全 转载记录 Linux环境变量设置方法总结 PATH.LD_LIBRARY_P ...
- Win10系列:VC++ XML文件解析
XML文件按照元素标记来存储数据,通过遍历这些元素标记可以得到XML文件中所保存的数据.在C++/CX的类库中并未定义用于解析XML文件的类,但C++提供了能解析XML文件的框架和类库,如msxml4 ...
- U深度U盘启动盘制作教程
① 下载u深度u盘启动盘制作工具 ② 一个能够正常使用的u盘(容量大小建议在4g以上) 第一步:安装u深度u盘启动盘制作工具 双击打开已下载好的安装包,点击窗口中立即安装即可: 等待安装完成后,可以点 ...
- ubuntu compile openjdk87
0. use oracle JDK,not OpenJDK 1. 遇到错误Error:./gamma: relocation error: /usr/lib/jvm/java-7-openjdk-am ...
- caffe操作技巧
查看网络结构: (1)利用caffe自带的Python,可以将*.prototxt保存为一张图片, sudo python python/draw_net.py *.prototxt *.png ...