北京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 ...
随机推荐
- 2.1命令行和JSON的配置「深入浅出ASP.NET Core系列」
希望给你3-5分钟的碎片化学习,可能是坐地铁.等公交,积少成多,水滴石穿,谢谢关注. 命令行配置 1.新建控制台项目 2.nuget引入microsoft.aspnetcore.all 这里要注意版本 ...
- C# 委托基础1.0
在C# 1.0中提出了一种新特性叫作:委托.委托本质上一种类型.是对特定方法的抽象,定义委托后,可以将方法封装,把方法当参数,传递 using System; using System.Collect ...
- 解决Spring MVC前台传参中文乱码问题
在web.xml文件中配置字符编码过滤器: <filter> <filter-name>CharacterEncoding</filter-name> <fi ...
- 初学Linux要掌握的命令
echo:打印,或者直接输出指定的字符串 语法:echo (选项) (参数) 选项:/a: 发出警告声 /b: 删除前一个字符 /c: 最后不加上换行符号 /f: 换行但光标仍旧停留在原来的位置 /n ...
- git status 显示中文乱码
场景 在使用git命令行查看当前 状态时, git status 显示中文文件乱码: 解决 修改git配置, git config --global core.quotepath false
- html&css学习一
HTML标签 HTML骨架 <HTML> <head> <title></title> </head> <body> </ ...
- 第二章 Linux目录学习
Linux 目录结构相对windows来说更简单,Linux 目录 以 斜杠 / 为根目录,其整体结构是以/为根的树状结构. 使用 tree -L 1 查看1级目录结构 /bin 常用的二进制命令目录 ...
- 高通方案的Android设备几种开机模式的进入与退出
高通方案的Android设备主要有以下几种开机模式,Android.EDL.Fastboot.Recovery和FFBM,其进入及退出的方式如下表. 开机模式 屏幕显示 冷启动 热启动 按键退出 命令 ...
- node.js微信小程序配置消息推送
在开发微信小程序时,有一个消息推送,它的解释是这样的. 消息推送具体的内容是下面的这个网址 https://developers.weixin.qq.com/miniprogram/dev/fra ...
- linux_FTP连接失败
service vsftpd status vim /etc/vstpd/vsfptd.conf service vsftpd restart service iptables status serv ...