杭电 1548 A strange lift(广搜)
A strange lift
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11341 Accepted Submission(s): 4289
the button "UP" , you will go up Ki floor,i.e,you will go to the i+Ki th floor,as the same, if you press the button "DOWN" , you will go down Ki floor,i.e,you will go to the i-Ki th floor. Of course, the lift can't go up high than N,and can't go down lower
than 1. For example, there is a buliding with 5 floors, and k1 = 3, k2 = 3,k3 = 1,k4 = 2, k5 = 5.Begining from the 1 st floor,you can press the button "UP", and you'll go up to the 4 th floor,and if you press the button "DOWN", the lift can't do it, because
it can't go down to the -2 th floor,as you know ,the -2 th floor isn't exist.
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.
5 1 5
3 3 1 2 5
0
3
<span style="font-size:24px;">#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std; const int maxn = 201;
int n, a, b;
int kp[maxn];
bool mark[maxn];
struct Node {
int floor;
int tme;
}; int BFS() {
memset(mark, false, sizeof(mark));
queue<Node> Q;
Node first, next_up, next_down;
first.tme = 0;
first.floor = a;
Q.push(first);
mark[a] = true; //标记 while (!Q.empty()) {
first = Q.front();
Q.pop(); if (first.floor == b) {
return first.tme;
}
next_up.floor = first.floor + kp[first.floor];
if (next_up.floor <= n && !mark[next_up.floor ]) {
next_up.tme = first.tme + 1;
mark[next_up.floor] = true;
Q.push(next_up);
}
next_down.floor = first.floor - kp[first.floor];
if (next_down.floor >= 1 && !mark[next_down.floor]) {
next_down.tme = first.tme + 1;
mark[next_down.floor] = true;
Q.push(next_down);
}
}
return -1;
} int main() { while (~scanf("%d", &n), n ) {
scanf("%d%d", &a, &b);
for (int i = 1; i <= n; i++) {
scanf("%d", &kp[i]);
} //输入
int res = BFS();
printf("%d\n", res);
}
}</span>
杭电 1548 A strange lift(广搜)的更多相关文章
- 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
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1548 A strange lift Description There is a strange li ...
- HDU 1548 A strange lift (广搜)
题目链接 Problem Description There is a strange lift.The lift can stop can at every floor as you want, a ...
- 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(BFS)
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 (Dijkstra)
A strange lift http://acm.hdu.edu.cn/showproblem.php?pid=1548 Problem Description There is a strange ...
- hdu 1548 A strange lift (bfs)
A strange lift Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- 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 搜索
A strange lift Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
随机推荐
- vs2012 jsoncpp 链接错误
解决: 项目->属性->C/C++->代码生成->运行库->设置与使用的.lib的版本一致.
- android中用Intent传数据,如果用传递的是一个类,就将类实现Parcelable接口
Parcelable,内存单位,跨进程使用,或者intent传递对象的时候使用.android中用Intent传数据,如果用传递的是一个对象,就将对象实现Parcelable接口,而不是将对象序列化. ...
- 使用antlr4及java实现snl语言的解释器
对于antlr4的基础使用,请参考我的前一篇文章<用antlr4来实现<按编译原理的思路设计的一个计算器>中的计算器>. 其实我对于antlr4的理解也仅限于那篇文章的范围,但 ...
- 【译】x86程序员手册28-7.7任务地址空间
7.7 Task Address Space 任务地址空间 The LDT selector and PDBR fields of the TSS give software systems desi ...
- 使用Spring框架的步骤
“好记性,不如烂笔头”.今天正式接触了Spring框架,第一次接触Spring框架感觉Spring框架简化了好多程序代码,开发效率大大提高.现在介绍使用Spring框架的步骤.(使用spring-fr ...
- 09C语言指针
C语言指针 地址 地址就是数据元素在内存中的位置表示: &变量名 #include <stdio.h> int main(){ int aa; unsigned int bb = ...
- Android studio开发-第一个应用
Android studio开发-第一个应用 上效果图 1.先创建布局文件 firstbutton.xml 代码 <?xml version="1.0" encoding=& ...
- cc.Node—Action
1: Action类是动作命令,我们创建Action,然后节点运行action就能够执行Action的动作; 2: Action分为两类: (1) 瞬时就完成的ActionInstant, (2) 要 ...
- 洛谷——P3389 【模板】高斯消元法
P3389 [模板]高斯消元法 以下内容都可省略,直接转大佬博客%%% 高斯消元总结 只会背板子的蒟蒻,高斯消元是什么,不知道诶,看到大佬们都会了这个水题,蒟蒻只好也来切一切 高斯消元最大用途就是解多 ...
- mysql数据库主从操作记录
master数据库已投入生产一段时间后,做主从复制的操作记录 环境: master库:172.18.237.13slave库:172.18.237.14 mysql版本说明: master:mysql ...