HDU_1548_A strange lift
题意:一部电梯(共top层),每一楼有一个数字k,在该层只能上k层或者下k层(up和down按钮),问从当前层到目标层按按钮的最小次数。
分析:广度优先搜索。
总结:初写BFS,仿照别人的代码,这方面要继续加强。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int k[],vis[];
int top,now,aim;
struct node
{
int floor,step;;
}; bool judge(int a)
{
if(a>=&&a<=top)
return ;
return ;
}
int BFS(node sta)
{
queue<node>q;
node now,next;
vis[sta.floor]=;
q.push(sta);
while(!q.empty())
{
now=q.front();
q.pop();
if(now.floor==aim)
return now.step;
for(int i=-; i<=; i+=)
{
if(!vis[now.floor+i*k[now.floor]]&&judge(now.floor+i*k[now.floor]))
{
next.floor=now.floor+i*k[now.floor];
next.step=now.step+;
vis[now.floor+i*k[now.floor]]=;
q.push(next);
}
}
}
return -;
} int main()
{ while(scanf("%d",&top)!=EOF&&top)
{
scanf("%d%d",&now,&aim);
for(int i=; i<=top; i++)
scanf("%d",&k[i]);
node a;
a.floor=now;
a.step=;
memset(vis,,sizeof(vis));
int ans=BFS(a);
printf("%d\n",ans);
}
return ;
}
HDU_1548_A strange lift的更多相关文章
- 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 (bfs / 最短路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1548 A strange lift Time Limit: 2000/1000 MS (Java/Ot ...
- A strange lift
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- 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
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1548 A strange lift Description There is a strange li ...
- 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 (Dijkstra)
A strange lift http://acm.hdu.edu.cn/showproblem.php?pid=1548 Problem Description There is a strange ...
- 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 搜索
A strange lift Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
随机推荐
- matlab Newton method
% Matlab script to illustrate Newton's method % to solve a nonlinear equation % this particular scri ...
- vux 全局使用 loading / toast / alert
1.入口文件 main.js import { LoadingPlugin, ToastPlugin, AlertPlugin } from 'vux' Vue.use(LoadingPlugin); ...
- 理解C语言中指针的声明以及复杂声明的语法
昨天刚把<C程序设计语言>中"指针与数组"章节读完,最终把心中的疑惑彻底解开了.如今记录下我对指针声明的理解.顺便说下怎样在C语言中创建复杂声明以及读懂复杂声明. 本文 ...
- 基于AR谱特征的声目标识别
本文第一部分先解释AR谱,但并不会给出太多的细节,第二部分介绍几种常见的语音中的特征.有些在之前的博文中已经用过.诸如过零率. 第三部分给出实际操作的过程及识别的效果.本文的目标是通过对DSP採集的声 ...
- ionic/cordova 真机调试
android下简单,连接手机后,直接: myProjectPath>ionic run android ios下比较麻烦点,要先装ios-deploy: sudo npm install - ...
- AWK学习总结(三) Records and Fields
AWK 记录和域 The NR Variable % awk '{print NR, $0}' employees 1 Tom Jones 4424 5/12/66 543354 2 Mary Ada ...
- luogu2827 蚯蚓
题目大意 本题中,我们将用符号[c]表示对c向下取整,例如:[3.0」= [3.1」= [3.9」=3. 蛐蛐国最近蚯蚓成灾了!隔壁跳蚤国的跳蚤也拿蚯蚓们没办法,蛐蛐国王只好去请神刀手来帮他们消灭蚯蚓 ...
- [RK3288][Android6.0] 音频调试方法小结【转】
本文转载自:http://blog.csdn.net/kris_fei/article/details/70053135 Platform: ROCKCHIPOS: Android 6.0Kernel ...
- 蓝书4.1-4.4 树状数组、RMQ问题、线段树、倍增求LCA
这章的数据结构题很真实 T1 排队 bzoj 1699 题目大意: 求静态一些区间的最大值-最小值 思路: ST表裸题 #include<iostream> #include<cst ...
- codeforces round #428 div2
A:暴力模拟,能加就加,如果累计到了8就加上,每次累积 #include<bits/stdc++.h> using namespace std; int main() { ; scanf( ...