题意:给你一个迷宫,迷宫有开始节点和结束节点,问你从开始走到结束的最小时间,其中,#代表这个点有毒气,身上必须带着氧气瓶才行,B代表每次进入这个点可以带一个氧气瓶,最多身上带五个,P代表进入这个点加速,不耗费时间

解题思路:就是bfs+优先队列,就是氧气瓶的地方麻烦点,我们只需要对于每个点,用一个多余的状态标记进入这个点身上氧气瓶的数量就可以了

代码:

#include<bits/stdc++.h>
using namespace std;
struct node
{
int x,y,step,cnt; node(int _x=,int _y=,int _step=,int _cnt=):x(_x),y(_y),step(_step),cnt(_cnt){}
friend bool operator<(node a,node b)
{
return a.step>b.step;
}
}tmp,now;
char s[][];
int n,m,sx,sy;
int next1[][]={{-,},{,},{,},{,-}};
int visit[][][];
int bfs(int x,int y)
{
priority_queue<node>que;
que.push(node(x,y,,));
while(!que.empty())
{
now=que.top();que.pop();
if(s[now.x][now.y]=='T')
return now.step;
for(int i=;i<;i++)
{ tmp.x=now.x+next1[i][];tmp.y=now.y+next1[i][];
if(tmp.x<||tmp.x>n||tmp.y<||tmp.y>m)
continue;
if(s[tmp.x][tmp.y]=='B')
{
tmp.cnt=min(,now.cnt+);tmp.step=now.step+;
if(!visit[tmp.x][tmp.y][tmp.cnt])
{
visit[tmp.x][tmp.y][tmp.cnt]=;
que.push(tmp);
}
}
else if(s[tmp.x][tmp.y]=='P')
{
tmp.cnt=now.cnt;tmp.step=now.step;
if(!visit[tmp.x][tmp.y][tmp.cnt])
{
visit[tmp.x][tmp.y][tmp.cnt]=;
que.push(tmp);
}
}
else if(s[tmp.x][tmp.y]=='#')
{
tmp.cnt=now.cnt-;tmp.step=now.step+;
if(tmp.cnt<)
continue;
if(!visit[tmp.x][tmp.y][tmp.cnt])
{
visit[tmp.x][tmp.y][tmp.cnt]=;
que.push(tmp);
}
}
else
{
tmp.cnt=now.cnt;tmp.step=now.step+;
if(!visit[tmp.x][tmp.y][tmp.cnt])
{
visit[tmp.x][tmp.y][tmp.cnt]=;
que.push(tmp);
}
}
} }
return -;
}
int main()
{
while(cin>>n>>m&&n&&m)
{
memset(visit,,sizeof(visit));
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
{
cin>>s[i][j];if(s[i][j]=='S'){sx=i;sy=j;}
}
int ans=bfs(sx,sy);
cout<<ans<<endl;
}
}

北京2018网络赛A题的更多相关文章

  1. Saving Tang Monk II HihoCoder - 1828 2018北京赛站网络赛A题

    <Journey to the West>(also <Monkey>) is one of the Four Great Classical Novels of Chines ...

  2. 北京2018网络赛 hihocoder#1828 : Saving Tang Monk II (BFS + DP +多开一维)

    hihocoder 1828 :https://hihocoder.com/problemset/problem/1828 学习参考:https://www.cnblogs.com/tobyw/p/9 ...

  3. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  4. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  5. ACM-ICPC 2019南昌网络赛F题 Megumi With String

    ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...

  6. ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval

    ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval 题目大意:给一个长度为n,值域为[1, n]的序列{a},要求支持m次操作: 单点修改 1 pos val 询 ...

  7. 2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)

    2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a squa ...

  8. HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  9. HDU 4768 Flyer (2013长春网络赛1010题,二分)

    Flyer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

随机推荐

  1. 【Vuex】vuex基本介绍与使用

    Vuex是什么? 官方解释: Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化.Vuex 也集 ...

  2. vue.js之动画篇

    本文引入类库的方式均采用CND的方式,可直接复制代码到编辑器中学习和测试 不使用动画切换元素 <div id="app"> <input type="b ...

  3. 解决在C#(.net)按字节数截取字符串最后出现乱码的问题

    最近需要用到按字节数截取字符串.在网上找了很多方法. Encoding.Default.GetString采用的DefaultEncoding.UTF8.GetBytes采用的是utf-8编码.这样当 ...

  4. java爬虫系列目录

    1. java爬虫系列第一讲-爬虫入门(爬取动作片列表) 2. java爬虫系列第二讲-爬取最新动作电影<海王>迅雷下载地址 3. java爬虫系列第三讲-获取页面中绝对路径的各种方法 4 ...

  5. OSS上传文件到阿里云

    最近做项目,需要上传文件,因为上传到项目路径下,感觉有时候也挺不方便的,就试了一下上传文件到阿里云oss上去了, oss的使用网上有很多介绍,都是去配置一下需要的数据,然后直接调用他的api就可以了. ...

  6. Java:配置环境(Mac)——Tomcat

    1.官网下载 2.把下载的文档解压,放到合适的路径下. 3.打开eclipse 4.在Apache文件夹下选择Tomcat的对应版本 5.选择刚才下载的文件 6.可以右键Start了

  7. python类的继承、封装和多态

    摘自https://www.cnblogs.com/evablogs/p/6724477.html 继承 1 2 3 4 5 6 7 8 class Person(object):     def _ ...

  8. Win 10 无法打开内核设备“\\.\Global\vmx86”问题

    Win 10操作系统, VMWareWorkstation10 无法打开内核设备"\\.\Global\vmx86": 系统找不到指定的文件.你想要在安装 VMware Works ...

  9. springboot整合shiro应用

    1.Shiro是Apache下的一个开源项目,我们称之为Apache Shiro.它是一个很易用与Java项目的的安全框架,提供了认证.授权.加密.会话管理,与spring Security 一样都是 ...

  10. mysql8.0绿色版安装及mysqldump备份

    1.下载mysql绿色版压缩包https://dev.mysql.com/downloads/mysql/ 2.解压到安装目录后,在根目录创建data文件夹 3.把mysql下的bin目录添加到环境变 ...