北京2018网络赛A题
题意:给你一个迷宫,迷宫有开始节点和结束节点,问你从开始走到结束的最小时间,其中,#代表这个点有毒气,身上必须带着氧气瓶才行,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题的更多相关文章
- Saving Tang Monk II HihoCoder - 1828 2018北京赛站网络赛A题
<Journey to the West>(also <Monkey>) is one of the Four Great Classical Novels of Chines ...
- 北京2018网络赛 hihocoder#1828 : Saving Tang Monk II (BFS + DP +多开一维)
hihocoder 1828 :https://hihocoder.com/problemset/problem/1828 学习参考:https://www.cnblogs.com/tobyw/p/9 ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
- ACM-ICPC 2019南昌网络赛F题 Megumi With String
ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...
- ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval
ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval 题目大意:给一个长度为n,值域为[1, n]的序列{a},要求支持m次操作: 单点修改 1 pos val 询 ...
- 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 ...
- 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 ...
- HDU 4768 Flyer (2013长春网络赛1010题,二分)
Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
随机推荐
- 权限管理系统之SpringBoot集成LayUI实现后台管理首页
万事开头难,昨天一直在构思用户权限管理系统怎么实现,实现哪些需求,采用什么技术等,也在网上百度了好多,计划使用SpringBoot + Mybatis + thymeleaf + LayUI + S ...
- day07 Class_field_method_反射
Class 由于Class类没有公共构造方法,所有创建Class的对象的方法有以下几种: 1).通过Class.forName()静态方法返回Class类的一个实例 Class cls=Class ...
- Servlet练习:实现增删改查的综合练习
---恢复内容开始--- 本文为原创,转载请注明出处:https://www.cnblogs.com/Tom-shushu/p/9383066.html 本篇内容主要介绍:通过Servlet,JSP, ...
- new会返回NULL空指针吗
c++中的new会返回NULL空指针吗 https://stackoverflow.com/questions/3389420/will-new-operator-return-null On a s ...
- 基于python的种子搜索网站,你懂得!
该项目是基于python的web类库django开发的一套web网站,给师弟做的毕业设计.本人的研究方向是一项关于搜索的研究项目.在该项目中,笔者开发了一个简单版的搜索网站,实现了对数据库数据的检索和 ...
- Android ble 蓝牙4.0 总结一
本文介绍Android ble 蓝牙4.0,也就是说API level >= 18,且支持蓝牙4.0的手机才可以使用,如果手机系统版本API level < 18,也是用不了蓝牙4.0的哦 ...
- 【English】十三、英语中的连词有哪些,都有什么作用
一.什么是连词 参考:https://m.hujiang.com/en_cixing/yylc/ 连词是一种虚词,用于连接单词.短语.从句或句子,在句子中不单独用作句子成分. 连词按其性质可分为并列连 ...
- [20190417]隐含参数_SPIN_COUNT.txt
[20190417]隐含参数_SPIN_COUNT.txt--//在探究latch spin计数之前,先简单探究_SPIN_COUNT.实际上oracle现在版本latch spin的数量不再是200 ...
- vue框架构建项目流程
构建项目流程: 1.全局查询:node -v 2.全局初始化:npm install --global vue-cli 3.模块化工程:vue init webpack myapp--->y,n ...
- Delphi 项目配置选项
打开项目设置窗口: 通过菜单:项目>选项 快捷键 :Shift+Ctrl+F11 Delphi编译器选项说明 Conditional defines 指定条件编译器指令中引用的符号. O ...