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 ...
随机推荐
- noj 2069 赵信的往事 [yy题 无限gcd]
njczy2010 2069 Accepted 31MS 224K 1351Byte G++ 2014-11-13 13:32:56.0 坑爹的无限gcd,,,尼玛想好久,原来要x对y算一次,y再 ...
- poj 3083 dfs,bfs
传送门 Children of the Candy Corn Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- jQuery on() 和 live
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...
- (1)Swing创建窗体
本系列使用Intellij IDEA 2017.3.4版本 一.运行窗体 1. 2. 3. 4. 5. 6. 给JPanel起个名字 -如From 7. 8. 9. 生成 import javax.s ...
- Flux --> Redux --> Redux React 入门 基础实例使用
本文的目的很简单,介绍Redux相关概念用法 及其在React项目中的基本使用 假设你会一些ES6.会一些React.有看过Redux相关的文章,这篇入门小文应该能帮助你理一下相关的知识 一般来说,推 ...
- Java8 时区DateTime API
原文:http://www.yiibai.com/java8/java8_zoneddateapi.html 时区日期时间的API正在使用当时区要被考虑时. 让我们来看看他们的操作. 选择使用任何编辑 ...
- http转成https
1.在阿里云服务器上购买一个AC证书,将证书下载下来 2.解压放在tomcat目录下,cert文件夹是我自己建的 3.修改tomcat的配置文件上面那个原来是被注掉的放开 把端口改为443,htt ...
- nrf51822中app_button 的应用
Button Handler(按键处理程序) 按键处理程序是使用GPIOTE(GPIO Task and Event)的处理机制实现的,为了防止按键的抖动.在GPIOTE event(事件)处理程序中 ...
- Git的使用 -- 用git玩翻github,结尾有惊喜!有惊喜!有惊喜!林妙妙看了说:牛呲呼啦带闪电 (三)(超详解)
简介 上一篇主要讲解的是Git安装及配置,这一篇就详细的从无到有的来用Git玩翻github. 一.什么是Github Github是全球最大的社交编程及代码托管网站(https://github.c ...
- WebService CXF Spring
web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=" ...