题意:给你一个迷宫,迷宫有开始节点和结束节点,问你从开始走到结束的最小时间,其中,#代表这个点有毒气,身上必须带着氧气瓶才行,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. 权限管理系统之SpringBoot集成LayUI实现后台管理首页

    万事开头难,昨天一直在构思用户权限管理系统怎么实现,实现哪些需求,采用什么技术等,也在网上百度了好多,计划使用SpringBoot + Mybatis + thymeleaf  + LayUI + S ...

  2. day07 Class_field_method_反射

    Class 由于Class类没有公共构造方法,所有创建Class的对象的方法有以下几种:   1).通过Class.forName()静态方法返回Class类的一个实例 Class cls=Class ...

  3. Servlet练习:实现增删改查的综合练习

    ---恢复内容开始--- 本文为原创,转载请注明出处:https://www.cnblogs.com/Tom-shushu/p/9383066.html 本篇内容主要介绍:通过Servlet,JSP, ...

  4. new会返回NULL空指针吗

    c++中的new会返回NULL空指针吗 https://stackoverflow.com/questions/3389420/will-new-operator-return-null On a s ...

  5. 基于python的种子搜索网站,你懂得!

    该项目是基于python的web类库django开发的一套web网站,给师弟做的毕业设计.本人的研究方向是一项关于搜索的研究项目.在该项目中,笔者开发了一个简单版的搜索网站,实现了对数据库数据的检索和 ...

  6. Android ble 蓝牙4.0 总结一

    本文介绍Android ble 蓝牙4.0,也就是说API level >= 18,且支持蓝牙4.0的手机才可以使用,如果手机系统版本API level < 18,也是用不了蓝牙4.0的哦 ...

  7. 【English】十三、英语中的连词有哪些,都有什么作用

    一.什么是连词 参考:https://m.hujiang.com/en_cixing/yylc/ 连词是一种虚词,用于连接单词.短语.从句或句子,在句子中不单独用作句子成分. 连词按其性质可分为并列连 ...

  8. [20190417]隐含参数_SPIN_COUNT.txt

    [20190417]隐含参数_SPIN_COUNT.txt--//在探究latch spin计数之前,先简单探究_SPIN_COUNT.实际上oracle现在版本latch spin的数量不再是200 ...

  9. vue框架构建项目流程

    构建项目流程: 1.全局查询:node -v 2.全局初始化:npm install --global vue-cli 3.模块化工程:vue init webpack myapp--->y,n ...

  10. Delphi 项目配置选项

    打开项目设置窗口: 通过菜单:项目>选项 快捷键    :Shift+Ctrl+F11 Delphi编译器选项说明  Conditional defines 指定条件编译器指令中引用的符号. O ...