Saving Tang Monk II
题目链接:http://hihocoder.com/contest/acmicpc2018beijingonline/problem/1
AC代码:
#include<bits/stdc++.h>
using namespace std;
# define inf 0x3f3f3f3f
# define maxn 100+10
# define ll long long
int n,m;
char a[maxn][maxn];
int f[2][4]= {{1,-1,0,0},{0,0,1,-1}};
int vis[maxn][maxn][10];
struct node
{
int x,y,b,step;
node() {}
node(int xx,int yy,int tt,int ww)
{
x=xx;
y=yy;
b=tt;
step=ww;
}
friend bool operator < (node a,node b)
{
return a.step>b.step;
}
};
void bfs(int t1,int t2)
{
priority_queue<node>q;
memset(vis,0,sizeof(vis));
q.push(node(t1,t2,0,0));
vis[t1][t2][0]=1;
while(!q.empty())
{
node temp=q.top();
q.pop();
// cout<<temp.x<<" "<<temp.y<<" "<<temp.b<<" "<<temp.step<<endl;
for(int i=0; i<4; i++)
{
node temp2;
int x=temp.x+f[0][i];
int y=temp.y+f[1][i];
if(x<=0||x>n||y<=0||y>m)continue;
temp2.x=x;
temp2.y=y;
temp2.b=temp.b;
temp2.step=temp.step+1;
if(a[x][y]=='B')
{
temp2.b=min(temp2.b+1,5);
}
else if(a[x][y]=='P')
{
temp2.step=max(temp2.step-1,0);
}
else if(a[x][y]=='#')
{
if(temp.b==0)continue;
temp2.b=max(temp2.b-1,0);
temp2.step++;
}
else if(a[x][y]=='T')
{
printf("%d\n",temp2.step);
return ;
}
if(vis[x][y][temp2.b])continue;
vis[x][y][temp2.b]=1;
q.push(temp2);
}
}
printf("%d\n",-1);
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
if(n+m==0)break;
int t1,t2;
getchar();
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
scanf("%c",&a[i][j]);
if(a[i][j]=='S')
{
t1=i;
t2=j;
}
}
getchar();
}
bfs(t1,t2);
}
return 0;
}
Saving Tang Monk II的更多相关文章
- Saving Tang Monk II(bfs+优先队列)
Saving Tang Monk II https://hihocoder.com/problemset/problem/1828 时间限制:1000ms 单点时限:1000ms 内存限制:256MB ...
- ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 A、Saving Tang Monk II 【状态搜索】
任意门:http://hihocoder.com/problemset/problem/1828 Saving Tang Monk II 时间限制:1000ms 单点时限:1000ms 内存限制:25 ...
- ACM-ICPC2018北京网络赛 Saving Tang Monk II(bfs+优先队列)
题目1 : Saving Tang Monk II 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 <Journey to the West>(also < ...
- hihocoder #1828 : Saving Tang Monk II(BFS)
描述 <Journey to the West>(also <Monkey>) is one of the Four Great Classical Novels of Chi ...
- hihocoder 1828 Saving Tang Monk II (DP+BFS)
题目链接 Problem Description <Journey to the West>(also <Monkey>) is one of the Four Great C ...
- Saving Tang Monk II HihoCoder - 1828 2018北京赛站网络赛A题
<Journey to the West>(also <Monkey>) is one of the Four Great Classical Novels of Chines ...
- ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 A.Saving Tang Monk II(优先队列广搜)
#include<bits/stdc++.h> using namespace std; ; ; char G[maxN][maxN]; ]; int n, m, sx, sy, ex, ...
- hihoCoder-1828 2018亚洲区预选赛北京赛站网络赛 A.Saving Tang Monk II BFS
题面 题意:N*M的网格图里,有起点S,终点T,然后有'.'表示一般房间,'#'表示毒气房间,进入毒气房间要消耗一个氧气瓶,而且要多停留一分钟,'B'表示放氧气瓶的房间,每次进入可以获得一个氧气瓶,最 ...
- 北京2018网络赛 hihocoder#1828 : Saving Tang Monk II (BFS + DP +多开一维)
hihocoder 1828 :https://hihocoder.com/problemset/problem/1828 学习参考:https://www.cnblogs.com/tobyw/p/9 ...
随机推荐
- 5分钟让你明白HTTP协议
一.HTTP简介 1.http协议介绍 HTTP协议(HyperText Transfer Protocol,超文本传输协议)是因特网上应用最为广泛的一种网络传输协议,所有的WWW文件都必须遵守这个标 ...
- 第二个Sprint冲刺第 八天(燃尽图)
因为今天停电了,所以我们也休息一天!
- 集美大学1414班软件工程个人作业2——个人作业2:APP案例分析
一.作业链接 个人作业2:APP案例分析 二.博文要求 通过分析你选中的产品,结合阅读<构建之法>,写一篇随笔,包含下述三个环节的所有要求. 第一部分 调研, 评测 下载软件并使用起来, ...
- beta圆桌 SUM UP
分工 黄家雄:基础页面 意见反馈 牛康文:基础页面 关于我们 姚志辉:登录注册页面修缮 魏璐炜:多界面修缮,用户使用调查,ppt制作 许斌:自动化测试 傅海涛:文件转换及列表,语音字幕,列表更新 徐明 ...
- python文本替换
file_data = '' str1 = ' str2 = ' with open(loginfofile, 'r+') as f: #打开文件,r+模式,读取 for line in f: if ...
- Docker 下 mysql 简单的 主从复制实现
1. 拉取镜像 docker pull mysql: 2. 运行这个镜像 docker run -d --name maser mysql: 3. 安装一些必要的软件 docker exec -it ...
- C++ STL 整理
一.一般介绍 STL(Standard Template Library),即标准模板库,是一个具有工业强度的,高效的C++程序库.它被容纳于C++标准程序库(C++ Standard Library ...
- 重启Hbase命令
注意先启动hadoop,记得重启zookeeper. 具体操作如下: cd hadoop-2.7.4/sbin/ && ./stop-all.sh && ./start ...
- ASP.NET MVC异常处理方案
异常处理是每一个系统都必须要有的功能,尤其对于Web系统而言,简单.统一的异常处理模式尤为重要,当打算使用ASP.NET MVC来做项目时,第一个数据录入页面就遇到了这个问题. 在之前的ASP.NET ...
- AOP 如果被代理对象的方法设置了参数 而代理对象的前置方法没有设置参数 则无法拦截到
AOP 如果被代理对象的方法设置了参数 而代理对象的前置方法没有设置参数 则无法拦截到