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 ...
随机推荐
- msp430项目编程37
msp430中项目---usb接口编程37 1.电路工作原理 2.代码(显示部分) 3.代码(功能实现) 4.项目总结
- 关于错误Access Violation和too many consecutive exceptions 解决方法
关于错误Access Violation和too many consecutive exceptions 解决方法 “如果DLL中用到了DELPHI的string类型,则DLL和主程序中都需要加上Sh ...
- Idea其他设置
一.生成javadoc Tools->Gerenate JavaDoc 1. 选择是整个项目还是模块还是单个文件 2. 文档输出路径 3. Locale 选择地区,这个决定了文档的语言,中文就是 ...
- HDU 6149 Valley Numer II(状压DP)
题目链接 HDU6149 百度之星复赛的题目……比赛的时候并没有做出来. 由于低点只有15个,所以我们可以考虑状压DP. 利用01背包的思想,依次考虑每个低点,然后枚举每个状态. 在每个状态里面任意枚 ...
- python 获取时间 存入文件
1读文件: file_path_name = '/home/robot/bzrobot_ws/src/bzrobot/bzrobot_comm/led_show_data/'+file_name+'. ...
- intellij idea springmvc web工程之helloworld
1.新建java工程 2.设置项目 2.添加jar包 3.配置web.xml <?xml version="1.0" encoding="UTF-8"?& ...
- 深入GCD(一): 基本概念和Dispatch Queue
什么是GCD?Grand Central Dispatch或者GCD,是一套低层API,提供了一种新的方法来进行并发程序编写.从基本功能上讲,GCD有点像NSOperationQueue,他们都允许程 ...
- 如何在ASP.NET Core自定义中间件中读取Request.Body和Response.Body的内容?
原文:如何在ASP.NET Core自定义中间件中读取Request.Body和Response.Body的内容? 文章名称: 如何在ASP.NET Core自定义中间件读取Request.Body和 ...
- 使用母版页时内容页如何使用css和javascript
由于网站的主要频道页和列表页的头部和底部都是一样的,如果将每个页面放在单独的页面中,当头部和底部需要更改时维护量太大.于是想把头部和底部做成母版页,频道页和列表页的具体内容放到内容页中.这样当头和底需 ...
- python 工具ScreenShoot
环境:windows python3 # -*- coding: UTF-8 -*- import time import os, win32gui, win32ui, win32con, win32 ...