hdu A strange lift
有起点和终点,有方向,有最少次数,所以这道题很明显是一道bfs的题目,这题要利用vist数组来标记已走过的楼层,因为这题里面已走过的楼层是不可能在走第二遍的。
第二次走和第一次走的选择没有任何的区别。
#include"iostream"
#include"stdio.h"
#include"string.h"
#include"algorithm"
#include"cmath"
#include"queue"
#define mx 205
using namespace std;
int n,a,b;
int k[mx];
int vist[mx];
struct node
{
int x,times;
friend bool operator<(node t1,node t2)
{
return t2.times<t1.times;
}
};
bool judge(int x)
{
if(x>=&&x<=n&&!vist[x]) return true;
return false;
}
void bfs()
{
node cur,next;
int i;
cur.x=a;cur.times=;
priority_queue<node>q;
q.push(cur);
while(!q.empty())
{
cur=q.top();
q.pop();
if(cur.x==b){cout<<cur.times<<endl;return;}
for(i=;i<;i++)
{
next.x=cur.x+pow(-,i)*k[cur.x];
if(judge(next.x))
{
next.times=cur.times+;
vist[next.x]=;
q.push(next);
}
}
}
cout<<-<<endl;
}
int main()
{
while(cin>>n,n)
{
int i;
cin>>a>>b;
for(i=;i<=n;i++) cin>>k[i];
memset(vist,,sizeof(vist));
vist[a]=;bfs();
}
return ;
}
hdu A strange lift的更多相关文章
- 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 ...
- 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 ...
- HDU 1548 A strange lift 搜索
A strange lift Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- hdu 1548 A strange lift (bfs)
A strange lift Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- 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 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 ...
随机推荐
- 【转】利用optimize、存储过程和系统表对mysql数据库表进行批量碎片清理释放表空间
本文收集于本人的笔记本,由于找不到原文出处.在此省略,如哪位知道可以联系我加上. 核心是利用mysql系统表和“optimize table 表名”命令,对mysql数据表进行空间的释放.由于dele ...
- apache AllowEncodedSlashes 允许URL中对路径分隔符进行编码
2013年11月29日 10:35:32 情景: 你想通过在当前的URL中记录来源页面的URL,以便处理完请求后再跳转回来源页: http://www.example1.com/refer/http: ...
- (转)使用SQLCMD在SQLServer执行多个脚本
概述: 作为DBA,经常要用开发人员提供的SQL脚本来更新正式数据库,但是一个比较合理的开发流程,当提交脚本给DBA执行的时候,可能已经有几百个sql文件,并且有执行顺序,如我现在工作的公司,十几个客 ...
- hdu5832 A water problem
A water problem Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- UVALive 7261 Xiongnu's Land (扫描线)
Wei Qing (died 106 BC) was a military general of the Western Han dynasty whose campaigns against the ...
- iOS开发——开发实战篇&版本控制SVN和Git使用详解
版本控制SVN和Git使用详解 公司的实际开发中,在天朝使用较多的还是SVN,因为SVN是集中式的,在天朝上班你们都懂的! -----------------svn--------- ...
- oracle 10g 学习之函数和存储过程(12)
一.函数 1. 函数的 helloworld: 返回一个 "helloworld--!" 的字符串 create or replace function helloworld re ...
- jquery easy ui 1.3.4 Tree树形菜单(9)
9.1.创建树形菜单 <ul id="tt" class="easyui-tree"> <li><span>第一级</ ...
- C# 6新特性及示例代码
今天推荐的其实是一个Github开源项目,不过这个开源项目是专门介绍C# 6的最新特性,并给出了示例代码. 我们知道,微软即将发布Windows 10和Visual Studio 2015,在VS20 ...
- PHP扩展开发
安装好php,进入安装目录. zbseoag@ubuntu:/usr/local/php-5.6.28/ext$ ./ext_skel --extname=mytest zbseoag@ubuntu: ...