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 ...
随机推荐
- “Linux内核分析”实验三报告
构造一个简单的Linux系统 张文俊+原创作品转载请注明出处+<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-10000290 ...
- Linux内核分析-两种方式使用同一个系统调用
实验部分 根据系统调用表,选取一个系统调用.我选得是mkdir这个系统调用,其系统调用号为39,即0x27 由于mkdir函数的原型为 int mkdir (const char *filename, ...
- ffmpeg格式转换
遇到有些wav文件在ubuntu下无法打开的情况,可以使用ffmpeg进行格式转换即可 ffmpeg -i 0.wav test.wav
- Beta阶段冲刺-1
1. 新成员 新加入成员,克克飞同学,任务是去弄公众号相关的部分. 队员 个人简介 博客地址 杨晨露 每天都在开会的PM http://www.cnblogs.com/ycll/ 游舒婷 每天都在装死 ...
- 80C51存储器与C51内存优化
80C51在物理结构上有四个存储空间:片内程序存储器.片外程序存储器.片内数据存储器和片外数据存储器.但在逻辑上,即从用户使用的角度上,80C51有三个存储空间:片内外统一编址的64KB的程序存储器地 ...
- Delphi中Form的position属性与代码自定义窗体位置
通过Form的Position属性可设置窗体的初始位置,如选择DesktopCenter为桌面中心,ScreenCenter为屏幕中心,等等. 这个属性在很多时候简化了程序代码. 但是,如果设置了po ...
- Spring之c3p0连接池配置和使用
1.导入包:c3p0和mchange包 2.代码实现方式: package helloworld.pools; import com.mchange.v2.c3p0.ComboPooledDataSo ...
- 当数据库字段与model字段规则不一致时候 需要在xml里面手工转换
- sql bak还原到新数据库
1 创建新数据库 TestDB 2 使用语句 use master restore database [TestDB] from disk = 'D:\SqlDataBak\SanJu\SanJu ...
- SQL 优化经验总结34条
我们要做到不但会写SQL,还要做到写出性能优良的SQL,以下为笔者学习.摘录.并汇总部分资料与大家分享! (1) 选择最有效率的表名顺序(只在基于规则的优化器中有效): ORACLE 的解析器按照 ...