HDU A strange lift
来源:互联网 发布:mac清理工具 编辑:程序博客网 时间:2024/05/16 06:49
A strange lift
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 148 Accepted Submission(s) : 67
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 53 3 1 2 50
Sample Output
3
#include<iostream>
#include<cstdio>
#include<map>
#include<queue>
int n, x, y, a[201];
using namespace std;
struct node
{
int h, step;
};
int main()
{
while (scanf_s("%d", &n) != EOF)
{
if (n == 0) break;
scanf_s("%d%d", &x, &y);
for (int i = 1; i <= n; i++)
scanf_s("%d", &a[i]);
queue<node> P;
node dc; dc.h = x, dc.step = 0; P.push(dc);
bool bb = 0;
while (!P.empty())
{
node dr = P.front(); P.pop();
if (dr.h == y)
{
printf("%d\n", dr.step);
bb = 1; break;
}
if (a[dr.h])
{
if (dr.h + a[dr.h] <= n)
{
node dd;
dd.h = dr.h + a[dr.h]; dd.step = dr.step + 1;
P.push(dd);
}
if (dr.h - a[dr.h] >= 1)
{
node dd;
dd.h = dr.h - a[dr.h]; dd.step = dr.step + 1;
P.push(dd);
}
a[dr.h] = 0;
}
}
if (bb == 0) printf("-1\n");
while (!P.empty()) P.pop();
}
return 0;
}
- HDU A strange lift
- HDU A strange lift
- A strange lift HDU
- A strange lift HDU
- HDU A strange lift
- A strange lift hdu 1548
- HDU 1548 A strange lift
- HDU 1548 A strange lift
- HDU 1548 A strange lift
- Hdu-1548 A strange lift
- HDU 1548 A strange lift
- HDU-1548-A strange lift
- hdu 1548 A strange lift
- HDU 1548-A strange lift
- HDU 1548 A strange lift
- hdu 1548 A strange lift
- hdu 1548 A strange lift
- HDU 1548 A strange lift
- venserver -- create and kill
- QT5.7 编译oracle驱动oci centos7
- 碾转相除求最大公约数 最大公倍数
- 51. N-Queens
- 年终奖时间到!这5个行业往年奖金拿得最多......
- HDU A strange lift
- nodejs资料
- 南瑞离职
- 陆金所—稳盈-e享统计-python爬虫
- 串口中怎样接收一个完整数据包的解析
- 通过时间来开关程序方法
- HDU 2602.Bone Collector
- Perceptrons
- leetcode 53 Maximum Subarray