HUD-1548

A strange lift

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24630    Accepted Submission(s): 8898

Problem Description

There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 <= Ki <= N) on every floor.The lift have just two buttons: up and down.When you at floor i,if you press 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"?

Input

The input consists of several test cases.,Each test case contains two lines.
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

For each case of the input output a interger, the least times you have to press the button when you on floor A,and you want to go to floor B.If you can‘t reach floor B,printf "-1".

Sample Input

5 1 5

3 3 1 2 5

0

Sample Output

3

BFS

附AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3
 4 int n,s,e;
 5 int ss[210],vis[210];
 6
 7 struct node{
 8     int x,step;
 9 };
10
11 int bfs(){
12     queue<node> Q;
13     node a,next;
14     a.x=s;
15     a.step=0;
16     vis[s]=1;
17     Q.push(a);
18     while(!Q.empty()){
19         a=Q.front();
20         Q.pop();
21         if(a.x==e)
22         return a.step;
23         for(int i=-1;i<=1;i+=2){
24             next=a;
25             next.x+=i*ss[next.x];
26             if(next.x<=0||next.x>n||vis[next.x])
27             continue;
28             vis[next.x]=1;
29             next.step++;
30             Q.push(next);
31         }
32     }
33     return -1;
34 }
35
36 int main(){
37     while(cin>>n&&n){
38         cin>>s>>e;
39         for(int i=1;i<=n;i++){
40             cin>>ss[i];
41         }
42         memset(vis,0,sizeof(vis));
43         cout<<bfs()<<endl;
44     }
45     return 0;
46 }
时间: 2024-10-27 03:13:41

HUD-1548的相关文章

三分 --- CSU 1548: Design road

Design road Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1548 Mean: 目的:从(0,0)到达(x,y).但是在0~x之间有n条平行于y轴的河,每条河位于xi处,无限长,wi宽,并分别给出了建立路和桥每公里的单价 求:到达目标的最小费用. analyse: 比赛的时候一直没想到思路,第二个样列怎么算都算不对,赛后才知道是三分. 首先把所有的桥移到最右端,然后三分枚举路和河的交点. Time

Hdu 1548 A strange lift(BFS)

Problem地址:http://acm.hdu.edu.cn/showproblem.php?pid=1548 一道简单的bfs,适合新手.你现在所在的电梯层为一个节点,而你从这个节点可以拜访另外两个节点(电梯向上走为一个节点,电梯向下走有一个节点),而拜访的时候自然也要避免拜访重复,否则会陷入死循环. #include <iostream> #include <queue> using namespace std; const int maxn = 200+10; int N,

HDU 1548 A strange lift【不错的最短路,spfa】

A strange lift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 21281    Accepted Submission(s): 7786 Problem Description There is a strange lift.The lift can stop can at every floor as you want

HDU 1548.A strange lift

A strange lift Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u SubmitStatusPracticeHDU 1548 Description There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 <= Ki <= N)

OSG的HUD抬头文字显示

原文:http://blog.csdn.net/tmljs1988/article/details/7562926 可以运行 1.       HUD流程图: 完整源代码如下: /*OSG中的HUD,文字总是显示在最前面*/ #include <osgDB/ReadFile> #include <osgViewer/Viewer> #include <osg/Geode> #include <osg/Depth> #include <osg/Camer

HUD总结

HUD 指示器/HUD/遮盖/蒙板 半透明的指示器如何实现 指示器的alpha = 1.0; 指示器的背景色是半透明的 1. 创建颜色 直接创建对应的颜色 + (UIColor *)blackColor; // 0.0 white + (UIColor *)darkGrayColor; // 0.333 white + (UIColor *)lightGrayColor; // 0.667 white + (UIColor *)whiteColor; // 1.0 white + (UIColo

遮罩 HUD 指示器 蒙板 弹窗

遮罩 HUD 指示器 蒙板 弹窗 UIAlertView的使用<代理方法处理按钮点击> UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"警告" message:@"是否要删除它?" delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil]; //加登录框 alertV

hdu 1548 (dijkstra解法)(一次AC就是爽)

恭喜福州大学杨楠获得[BestCoder Round #4]冠军(iPad Mini一部) <BestCoder用户手册>下载 A strange lift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11670    Accepted Submission(s): 4430 Problem Description There is

HUD 2023 求平均数

求平均成绩 Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 61990????Accepted Submission(s): 14860 Problem Description 假设一个班有n(n<=50)个学生,每人考m(m<=5)门课,求每个学生的平均成绩和每门课的平均成绩,并输出各科成绩均大于等于平均成绩的学生数量. ? ? In

hud 1312 Red and Black

题目: 链接:点击打开链接 题意: DFS搜索 算法: dfs 思路: 简单题 代码: #include<iostream> #include<cstdio> #include<cstring> using namespace std; int w,h; char s[30][30]; int vis[30][30]; int cnt; void dfs(int x,int y) { if(s[x][y] == '#' || vis[x][y]) return ; if