• 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 !!!

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <queue>
     6 using namespace std;
     7 
     8 const int maxn = 200 + 10;
     9 int vis[maxn], k[maxn];
    10 
    11 struct node
    12 {
    13     int f, step;
    14 }st, s, next;
    15 
    16 int main()
    17 {
    18     int n, a, b;
    19     while (scanf("%d", &n) != EOF)
    20     {
    21         if (n == 0)
    22             break;
    23         scanf("%d%d", &a, &b);
    24         for (int i = 1; i <= n; i++)
    25         {
    26             scanf("%d", &k[i]);
    27             vis[i] = 0;
    28         }
    29         int flag = 0;
    30         queue<node> q;     // 这个东西在main外声明就wa!!!
    31         st.f = a;
    32         st.step = 0;
    33         q.push(st);
    34         vis[st.f] = 1;
    35         while (!q.empty())
    36         {
    37             s = q.front();
    38             q.pop();
    39             if (s.f == b)
    40             {
    41                 flag = 1;
    42                 break;
    43             }
    44             st.f = s.f + k[s.f];
    45             next.f = s.f - k[s.f];
    46             if (st.f >= 1 && st.f <= n && !vis[st.f])
    47             {
    48                 vis[st.f] = 1;
    49                 st.step = s.step + 1;
    50                 q.push(st);
    51             }
    52             if (next.f >= 1 && next.f <= n && !vis[next.f])
    53             {
    54                 vis[next.f] = 1;
    55                 next.step = s.step + 1;
    56                 q.push(next);
    57             }
    58         }
    59         printf("%d
    ", flag ? s.step : -1);
    60     }
    61     return 0;
    62 }
  • 相关阅读:
    「考试」省选27
    「考试」省选26
    「考试」省选25
    $dy$讲课总结
    「笔记」$Min\_25$筛
    「考试」省选24
    「总结」多项式生成函数例题(4)
    「总结」多项式生成函数相关(4)
    「考试」省选23
    「总结」后缀3
  • 原文地址:https://www.cnblogs.com/windysai/p/3906065.html
Copyright © 2020-2023  润新知