HDU 1548 A strange lift 题解
A strange lift
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 33697 Accepted Submission(s): 12038
Here comes the problem: when you are on floor A,and you want to go to floor B,how many times at least he has to press the button "UP" or "DOWN"?
The first line contains three integers N ,A,B( 1 <= N,A,B <= 200) which describe above,The second line consist N integers k1,k2,....kn.
A single 0 indicate the end of the input.
3 3 1 2 5
0
//Author:LanceYu
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<fstream>
#include<iosfwd>
#include<sstream>
#include<fstream>
#include<cwchar>
#include<iomanip>
#include<ostream>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<ctime>
#include<algorithm>
#include<complex>
#include<cmath>
#include<valarray>
#include<bitset>
#include<iterator>
#define ll long long
using namespace std;
const double clf=1e-;
//const double e=2.718281828;
const double PI=3.141592653589793;
const int MMAX=;
//priority_queue<int>p;
//priority_queue<int,vector<int>,greater<int> >pq;
struct node
{
int x,step;
};
int n,start,last;
int dir[][],vis[];//dir分为两个方向,向上和向下
int bfs(int start,int last)
{
int i;
queue<node> q;
q.push(node{start,});
vis[start]=;
while(!q.empty())
{
node t=q.front();
q.pop();
if(t.x==last)
return t.step;
for(int i=;i<;i++)
{
int dx=t.x+dir[i][t.x];
if(dx>=&&dx<n&&!vis[dx])//一维深度搜索
{
vis[dx]=;
q.push(node{dx,t.step+});
}
}
}
return -;
}
int main()
{
int temp;
while(scanf("%d",&n)!=EOF)//这里输入要分开,因为输入为0时停止
{
if(n==)
return ;
scanf("%d%d",&start,&last);
memset(vis,,sizeof(vis));
for(int i=;i<n;i++)//每一层的数据录入,包括两个方向
{
scanf("%d",&temp);
dir[][i]=temp;
dir[][i]=-temp;
}
int ans=bfs(start-,last-);//注意此处要-1,受到数组的限制和影响
printf("%d\n",ans);
}
return ;
}
2018-11-16 01:05:38 Author:LanceYu
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 宽搜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 http://acm.hdu.edu.cn/showproblem.php?pid=1548 Problem Description There is a strange ...
- 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 ...
- Hdoj 1548.A strange lift 题解
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(BFS)
Problem Description There is a strange lift.The lift can stop can at every floor as you want, and th ...
随机推荐
- ESP8266 AT指令开发(基于STC89C52单片机): 硬件使用说明
实物图 硬件说明 开发板板载说明: 1.主控芯片: STC89C52 2.Wi-Fi模块: ESP8266 3.温湿度传感器: DHT11 4.液晶屏: IIC OLED 5.继电器: 220V 10 ...
- node.js与mysql数据库的交互
我们已经建好了数据库也建好了表,现在我们想查询数据库表中的内容,应该怎么做呢? 代码如下: var mysql = require('mysql'); //导入mysql包模块 var connect ...
- [LeetCode] 34. Find First and Last Position of Element in Sorted Array 在有序数组中查找元素的第一个和最后一个位置
Given an array of integers nums sorted in ascending order, find the starting and ending position of ...
- Ubuntu16LTS使用笔记(Server版)
环境测试:Ubuntu Server 16.04.06 x64 虚拟机 以下均需要root权限,请sudo 或 su root 解决只有先启动Windows再重启到Linux才能使用usb网卡的问题: ...
- C++中vector小学习,顺便查了下<stdio.h>(或<cstdio>)
今天看书,邻桌在看<C++ Primer>,拿过来看了一会儿.以前比较少用vector容器,看了下后,瞬间觉得好腻害的样子,就想试一下.嗯,就是试一下而已.(代码可能网上都差不多,有参考) ...
- Eclipse JAX-RS (REST Web Services) 2.0 requires Java 1.6 or newer
pom.xml文件中添加: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins&l ...
- LeetCode 561:数组拆分 I Array Partition I
文章全部来自公众号:爱写bug 算法是一个程序的灵魂. Given an array of 2n integers, your task is to group these integers into ...
- Docker 安装 Request Tracker 工单系统
1.需求 docker 安装工单系统 Request Tracker,并需要支持 LDAP 登入. 2.制作镜像 1)request-tracker-base镜像 第一个镜像安装一些基础支持软件,如 ...
- char (*a)[N] 与 char* a[M]区别
已知第二维 char (*a)[N]; //指向数组的指针,实际上这里的N并没有实际的约束意义,平时也很少这么用a = (char (*)[N])malloc(sizeof(char *) * m); ...
- Spark Core知识点复习-1
Day1111 Spark任务调度 Spark几个重要组件 Spark Core RDD的概念和特性 生成RDD的两种类型 RDD算子的两种类型 算子练习 分区 RDD的依赖关系 DAG:有向无环图 ...