题意:给你一个迷宫,迷宫有开始节点和结束节点,问你从开始走到结束的最小时间,其中,#代表这个点有毒气,身上必须带着氧气瓶才行,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. 校园生活app结对开发第一天

    今天刚开始开发,要安装android studio及熟悉软件操作

  2. 解决Spring MVC前台传参中文乱码问题

    在web.xml文件中配置字符编码过滤器: <filter> <filter-name>CharacterEncoding</filter-name> <fi ...

  3. 《JavaScript高级程序设计》笔记:客户端检测(九)

    能力检测 在编写代码之前先检测特定浏览器的能力.例如,脚本在调用某个函数之前,可能要先检测该函数首付存在.这种检测方法将开发人员从考虑具体的浏览器类型和版本中解放出来,让他们把注意力集中到相应的能力是 ...

  4. python的学习笔记01_5文件操作

    一,文件操作基本流程. 计算机系统分为:计算机硬件,操作系统,应用程序三部分. 我们用python或其他语言编写的应用程序若想要把数据永久保存下来,必须要保存于硬盘中,这就涉及到应用程序要操作硬件,众 ...

  5. Dynamics 365-CRM又报看不懂的错误了

    在CRM上执行各种操作,时不时会碰到各种问题,尤其是CRM环境里包含越来越多定制的时候.有的问题在CRM弹出的错误提示框,一目了然:而有的,可能就是简单的提示:SQL Error. 这个时候我们可能都 ...

  6. google zxing android扫描优化&解析

    这里先给出zxing包的源码地址 zip包:https://codeload.github.com/zxing/zxing/zip/master Github:https://github.com/z ...

  7. typescript中的泛型

    泛型:软件工程中,我们不仅要创建一致的定义良好的API,同时也要考虑可重用性. 组件不仅能够支持当前的数据类型,同时也能支持未来的数据类型,这在创建大型系统时为你提供了十分灵活的功能. 在像C#和Ja ...

  8. 工具资源系列之给虚拟机装个ubantu

    前文我们已经讲解了如何在 mac 系统上安装虚拟机软件,这节我们接着讲解如何利用虚拟机安装 Ubuntu 镜像. 安装镜像的大致步骤基本相同,只不过是配置项略显不同而已,如果需要安装其他系统镜像,请参 ...

  9. 数据库【mongodb篇】练习操作

    本文的目标是通过大量的示例,来更好的理解如果在Mongodb中进行数据操作: 初入客户端刚利用 mongod命令进入客户端环境,此时对数据库一无所知: 举目四望,想知道现在有哪些数据库,   show ...

  10. DDctf 新得

    滴这道题当时做的时候只做到了看到index.php的源码 当时给了一个博客的提示猜到是swp的那个 但是没有想到是里面的 文件就没有做了,然后在看了wp过后就明白了 访问博客我文章里面的文章里面的pr ...