hdu 1548 A strange lift
A strange lift
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 56 Accepted Submission(s) : 15
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
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"?
Input
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.
Output
Sample Input
5 1 5 3 3 1 2 5 0
Sample Output
3
用广搜,注意标记
#include<cstdio> #include<cstring> #include<queue> #include<cstdlib> using namespace std; int map[205]; int floor[205]; int n; struct Node {int x,step; }info; bool f(int x) {if(x<1||x>n){return false;}return true; } int bfs(int sx,int sy) {info.x=sx,info.step=0;queue<Node>q;q.push(info);while(!q.empty()){Node pos=q.front();q.pop();if(pos.x==sy){return pos.step;}info.x=pos.x+floor[pos.x];if(f(info.x)&&!map[info.x]){map[info.x]=1; //标记info.step=pos.step+1;q.push(info);}info.x=pos.x-floor[pos.x];if(f(info.x)&&!map[info.x]){map[info.x]=1; //标记info.step=pos.step+1;q.push(info);}}return -1; } int main() {int A,B;while(scanf("%d",&n)!=EOF&&n){memset(map,0,sizeof(map));scanf("%d%d",&A,&B);map[A]=1;for(int i=1;i<=n;i++){scanf("%d",&floor[i]);}printf("%d\n",bfs(A,B));}return 0; }
转载于:https://www.cnblogs.com/gantaiyuan/p/3211963.html
hdu 1548 A strange lift相关推荐
- hdu 1548 A strange lift (BFS)
解题思路:BFS 注意点:每次查询结束后,要清空队列 #include <iostream> #include <queue> #include <cstring> ...
- A strange lift HDU - 1548(基础广搜)
There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 ...
- HDU A strange lift
A strange lift Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- SDAU 搜索专题 13 A strange lift
1:问题描述 Problem Description There is a strange lift.The lift can stop can at every floor as you want, ...
- HDU1548:A strange lift(Dijkstra或BFS)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1548 题意:电梯每层有一个数,例如第n层有个数k, 那么这一层只能上k层或下k层,但是不能低于一层或高 ...
- poj 1564 Sum It Up | zoj 1711 | hdu 1548 (dfs + 剪枝 or 判重)
Sum It Up Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Sub ...
- 【HDU - 2899】 Strange fuction(二分或三分,求导)
题干: Now, here is a fuction: F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100) Can you fi ...
- hdu 1548 升降梯
题目大意:有一个升降机,它有两个按钮UP和DOWN,给你一些数i表示层数,并且每层对应的Ki,如果按UP按钮,会从第i层升到第i+Ki层:如果按了DOWN则会从第i层降到第i-Ki层:并规定能到的层数 ...
- 杭电OJ分类题目(4)-Graph
原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(4) HDU Graph Theory - U ...
最新文章
- Django Admin 录入中文错误解决办法
- 商汤首付56亿!上海建成亚洲最大AI“发电厂”,万亿参数大模型训练无压力
- C++ 动态内存管理:c/c++的动态内存管理,new/delete,operator new/delete,placement-new, 内存泄漏
- linux 查看内存用量_正确计算linux系统内存使用率
- 【新年巨献】计算机类国际英文EI(JA)期刊限量推荐
- 一、Ajax跨域访问
- hausaufgabe--python 20- usage of Closure
- 2.python中的矩阵、多维数组----numpy
- linux里用户权限:~$,/$,~#,/#的区别与含义
- 已修复的bug: 简书文章长标题换行异常,标题配图异常,首页配图异常
- 实践项目2 图书管理系统
- 汉王考勤系统服务器IP,汉王人脸识别考勤客户端使用说明
- vs2005安装和部署项目
- oracle的dual用法
- 运动数据采集,医疗数据采集
- 重磅推出:2019中国开源年度报告
- 【乐理学习】音程 升降调 力度标记
- 配音软件永久免费的有哪些?这几款免费的配音软件绝对适合你
- 1248 NYOJ 海岛争霸
- 1007: 求正方形面积
热门文章
- Java实现markdown转html,并且生成TOC目录
- php自定义函数出现乱码,php的imagettftext 函数出现乱码的解决方法
- 计算机学具制作,一种具有防护功能的计算机编程学具的制作方法
- AOP通过开启注解方式自动注入值
- nginx添加stream模块1.20
- [k8s] 第八章 数据存储
- Docker(五):Docker Volume
- 获得虚拟服务器相对路径,在web应用中获取相对路径和绝对路径
- python矩阵处理库_用于处理非常大的矩阵的Python库
- 清华大佬教你一招最便捷搭建 Zookeeper 的方法!