题目链接: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 解题报告的更多相关文章

  1. hdu 1548 A strange lift

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1548 A strange lift Description There is a strange li ...

  2. HDU 1548 A strange lift (Dijkstra)

    A strange lift http://acm.hdu.edu.cn/showproblem.php?pid=1548 Problem Description There is a strange ...

  3. 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 ...

  4. HDU 1548 A strange lift (最短路/Dijkstra)

    题目链接: 传送门 A strange lift Time Limit: 1000MS     Memory Limit: 32768 K Description There is a strange ...

  5. 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 ...

  6. HDU 1548 A strange lift 搜索

    A strange lift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  7. hdu 1548 A strange lift (bfs)

    A strange lift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  8. 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 ...

  9. HDU 1548 A strange lift (广搜)

    题目链接 Problem Description There is a strange lift.The lift can stop can at every floor as you want, a ...

随机推荐

  1. NOIP 前夕 模板整理

    归并排序: #include<iostream> #include<cstdio> #include<cstring> using namespace std; ] ...

  2. (12)centos之stmp服务器

    yum remove sendmail #卸载sendmail  

  3. 洛谷——P2298 Mzc和男家丁的游戏

    P2298 Mzc和男家丁的游戏 题目背景 mzc与djn的第二弹. 题目描述 mzc家很有钱(开玩笑),他家有n个男家丁(做过上一弹的都知道).他把她们召集在了一起,他们决定玩捉迷藏.现在mzc要来 ...

  4. Linux常用C函数-接口处理篇(网络通信函数)

    接口处理篇accept,bind,connect,endprotoent,endservent,getsockopt,htonl,htons,inet_addr,inet_aton,inet_ntoa ...

  5. 在Nginx上部署ThinkPHP,解决Pathinfo问题

    在Nginx上部署ThinkPHP,解决Pathinfo问题 事实上.要解决nginx不支持pathinfo的问题.有两个解决思路,一是不使用pathinfo模式,二是改动nginx的配置文件,使它支 ...

  6. Unity ----- 对象池GameObjectPool

    孙广东 2014.6.28 非常早之前看到的外国文章,认为不错,分享一下. 对象池在AssetStore中也是有非常多插件的,可是有些重了.自己写一个轻量的岂不是非常好. 当你须要创建大量某种类型对象 ...

  7. javascript 复制粘贴操作

    function CopyCode(key){ var trElements = document.all.tags("tr");//获取tr元素 var i; for(i = 0 ...

  8. bzoj1601【Usaco2008 Oct】灌水

    1601: [Usaco2008 Oct]灌水 Time Limit: 5 Sec  Memory Limit: 162 MB Submit: 1589  Solved: 1035 [Submit][ ...

  9. LeetCode232 Implement Queue using Stacks Java 题解

    题目: Implement the following operations of a queue using stacks. push(x) -- Push element x to the bac ...

  10. 理解OpenStack认证:Keystone PKI

    原文链接: https://www.mirantis.com/blog/understanding-openstack-authentication-keystone-pki/ The latest ...