hdu 1548 A strange lift 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1548
题目意思:给出 n 个 floor 你,每个floor 有一个数k,按下它可以到达 floor + k 或者 floor - k的位置。问从floor A 到 floor B 最少的按lift 次数是多少。
hdu 真是!!!!!
queue<node> q 写在main 外就 wa了!!! = = 汗!!!
还专门瞪大双眼对照别人AC的代码,看了一遍又一遍,以为色盲了= =,可恶HDU !!!
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
using namespace std; const int maxn = + ;
int vis[maxn], k[maxn]; struct node
{
int f, step;
}st, s, next; int main()
{
int n, a, b;
while (scanf("%d", &n) != EOF)
{
if (n == )
break;
scanf("%d%d", &a, &b);
for (int i = ; i <= n; i++)
{
scanf("%d", &k[i]);
vis[i] = ;
}
int flag = ;
queue<node> q; // 这个东西在main外声明就wa!!!
st.f = a;
st.step = ;
q.push(st);
vis[st.f] = ;
while (!q.empty())
{
s = q.front();
q.pop();
if (s.f == b)
{
flag = ;
break;
}
st.f = s.f + k[s.f];
next.f = s.f - k[s.f];
if (st.f >= && st.f <= n && !vis[st.f])
{
vis[st.f] = ;
st.step = s.step + ;
q.push(st);
}
if (next.f >= && next.f <= n && !vis[next.f])
{
vis[next.f] = ;
next.step = s.step + ;
q.push(next);
}
}
printf("%d\n", flag ? s.step : -);
}
return ;
}
hdu 1548 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 (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+优先队列
题目链接: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 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 ...
- 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 (广搜)
题目链接 Problem Description There is a strange lift.The lift can stop can at every floor as you want, a ...
随机推荐
- 洛谷P2483 Bzoj1975 [SDOI2010]魔法猪学院
题目描述 iPig在假期来到了传说中的魔法猪学院,开始为期两个月的魔法猪训练.经过了一周理论知识和一周基本魔法的学习之后,iPig对猪世界的世界本原有了很多的了解:众所周知,世界是由元素构成的:元素与 ...
- MySQL中blob 与 text
BLOB是一个二进制大对象,可以容纳可变数量的数据.有4种BLOB类型:TINYBLOB.BLOB.MEDIUMBLOB和LONGBLOB.它们只是可容纳值的最大长度不同. 有4种TEXT类型:TIN ...
- 使用FL2440之问题1
随机送的usb转串口线(一头usb一头9针,蓝色),写明HL340,装上驱动后运行正常,但电脑设备管理器显示的却是CH340,以前还用过PL2303,百度总结一下他们的区别: CH340,PL2303 ...
- Xcode打包应用为ipa
Xcode教程 Xcode4发布测试 打包Archive操作是本文要介绍的内容,发布测试的最后一步打包(Archive),Xcode4帮助文档有比较详细介绍,但是居然是错的,这里说明一下. 1.设置& ...
- python(3)- 常用快捷键及基础命令
- 从Activity的启动流程理解Binder
简述 关于Activity启动流程和Binder的文章很多,大多数是分开来讲的,本文将二者结合起来,着重分析启动流程中跨进程方面的细节,其实,启动流程看似调用繁多,主要是复杂在Activity栈管理等 ...
- P2085 最小函数值 洛谷
https://www.luogu.org/problem/show?pid=2085 题目描述 有n个函数,分别为F1,F2,...,Fn.定义Fi(x)=Ai*x^2+Bi*x+Ci (x∈N*) ...
- linux命令stat,查看文件详细信息
可以查看文件的各类具体信息:文件权限的数字形式0664:uid.gid的权限的数字形式等 更多用法参考stat --help lsattr test.sh 查看文件的其他属性:只读属性.只可以追加写属 ...
- win7系统使用engine进行开发报错,“未能加载文件或程序集”
http://www.gisall.com/wordpress/?p=7161 使用vs2010加 arcengine 开发winfrom应用,新建了uc,拖了几个控件后,编译,报未能加载文件或程序集 ...
- 关于android 使用bitmap的OOM心得和解决方式
android开发,从2010年開始学习到如今的独立完毕一个app,这漫长的四年,已经经历了非常多次bug的折磨.无数次的加班训练.然而,自以为自己已经比較了解android了,却近期在一个项目上.由 ...