题目链接: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的更多相关文章

  1. Saving Tang Monk II(bfs+优先队列)

    Saving Tang Monk II https://hihocoder.com/problemset/problem/1828 时间限制:1000ms 单点时限:1000ms 内存限制:256MB ...

  2. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 A、Saving Tang Monk II 【状态搜索】

    任意门:http://hihocoder.com/problemset/problem/1828 Saving Tang Monk II 时间限制:1000ms 单点时限:1000ms 内存限制:25 ...

  3. ACM-ICPC2018北京网络赛 Saving Tang Monk II(bfs+优先队列)

    题目1 : Saving Tang Monk II 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 <Journey to the West>(also < ...

  4. hihocoder #1828 : Saving Tang Monk II(BFS)

    描述 <Journey to the West>(also <Monkey>) is one of the Four Great Classical Novels of Chi ...

  5. hihocoder 1828 Saving Tang Monk II (DP+BFS)

    题目链接 Problem Description <Journey to the West>(also <Monkey>) is one of the Four Great C ...

  6. Saving Tang Monk II HihoCoder - 1828 2018北京赛站网络赛A题

    <Journey to the West>(also <Monkey>) is one of the Four Great Classical Novels of Chines ...

  7. 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, ...

  8. hihoCoder-1828 2018亚洲区预选赛北京赛站网络赛 A.Saving Tang Monk II BFS

    题面 题意:N*M的网格图里,有起点S,终点T,然后有'.'表示一般房间,'#'表示毒气房间,进入毒气房间要消耗一个氧气瓶,而且要多停留一分钟,'B'表示放氧气瓶的房间,每次进入可以获得一个氧气瓶,最 ...

  9. 北京2018网络赛 hihocoder#1828 : Saving Tang Monk II (BFS + DP +多开一维)

    hihocoder 1828 :https://hihocoder.com/problemset/problem/1828 学习参考:https://www.cnblogs.com/tobyw/p/9 ...

随机推荐

  1. Alpha阶段_团队分数分配

    小组成员 分数分配 薄霖 74 徐越 65 赵庶宏 65 赵铭 41 武鑫 39 卞忠昊 36 叶能端 30

  2. 小学四则运算APP 第一个冲刺阶段 第四天

    团队成员:陈淑筠.杨家安.陈曦 团队选题:小学四则运算APP 第一次冲刺阶段时间:11.17~11.27 本次发布我们增加了CalculatorsActivity.java.YunsuanActivi ...

  3. Django 图片上传、存储与显示

    参考博客:http://www.cognize.me/2016/05/09/djangopic 开始之前要先安装python图像处理库:pip install --use-wheel Pillow 一 ...

  4. [知乎]BAT占线

    黑色自有,蓝色全资收够,红色入股. https://www.zhihu.com/question/304396738/answer/547766603

  5. Json序列化循环引用的问题

    今天在发布接口的时候出突然出现了一个问题,报错代码为: 1 An exception has occurred while using the formatter 'JsonMediaTypeForm ...

  6. 1643【例 3】Fibonacci 前 n 项和

    1643:[例 3]Fibonacci 前 n 项和 时间限制: 1000 ms         内存限制: 524288 KB sol:这题应该挺水的吧,就像个板子一样 1 0 01 1 0   * ...

  7. angular学习总结

    因为学习需要,要配置一系列环境,中间又出了很多各种各样的花式错误,因此当做个人总结记录一下.一.vs1. 完全卸载VS2013找到vs2013的安装包,如图 打开cmd命令行窗口,cd到安装包下的vs ...

  8. Luogu5162 WD与积木(生成函数+多项式求逆)

    显然的做法是求出斯特林数,但没有什么优化空间. 考虑一种暴力dp,即设f[i]为i块积木的所有方案层数之和,g[i]为i块积木的方案数.转移时枚举第一层是哪些积木,于是有f[i]=g[i]+ΣC(i, ...

  9. Sum 南京网络赛J题

    题意: 统计每个数的因子的对数,如果因子能被某个平方数整除,则不统计在内,每对因子有序 解析: 我们对某个数n进行质因子分解,如果某个质因子的指数大于2则 f(n) = 0, 例 N = X3 * M ...

  10. Could not resolve placeholder 'jdbc.driver'

     将jdbc.driver=oracle.jdbc.OracleDriver 改成jdbc.driver=oracle.jdbc.driver.OracleDriver     或者反过来修改.    ...