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 ...
随机推荐
- 关于maven:调整你的maven的jdk版本为 xxxx
找到你的.m2文件 在里面添加一下信息 实例 将其更改成1.7 <profiles> <profile> <id>jdk-1.7</id> <! ...
- [软工课程博客] 求解第N个素数
任务 求解第 10,0000.100,0000.1000,0000 ... 个素数(要求精确解). 想法 Sieve of Eratosthenes 学习初等数论的时候曾经学过埃拉托斯特尼筛法(Sie ...
- 云平台项目--学习经验--jsrender前端渲染模板
jsrender的好处:可以预先自定义一些固定的html标签,在需要显示数据的时候,可以直接传入真实的数据并显示在web页面中,避免了Js编写中的复杂过程:针对高性能和纯字符串渲染并优化,不需要依赖D ...
- Visual Studio 2015的安装和简单的测试
首先是Visual Studio 2015的安装 Visual Studio是微软开发的一套基于组件的软件开发工具,目前最新的版本是2015. 在 I Tell you 网站下载Visual Stud ...
- 第五周可执行代码 以及 Canvas 制作个人PSP分类饼图
第五周可执行代码已经上传github,地址是https://github.com/yanyige/CourseWork/tree/master/Week4.以及效果在http://yanyige.gi ...
- jmeter测试soap协议时候 路径不需要添加
- Nginx upstream 配置
1.轮询(默认)每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. 2.weight指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况.例如:u ...
- poj2828 Buy Tickets (线段树 插队问题)
Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 22097 Accepted: 10834 Des ...
- 【刷题】BZOJ 4916 神犇和蒟蒻
Description 很久很久以前,有一只神犇叫yzy; 很久很久之后,有一只蒟蒻叫lty; Input 请你读入一个整数N;1<=N<=1E9,A.B模1E9+7; Output 请你 ...
- CF1110D Jongmah(DP)
题目链接:CF原网 洛谷 题目大意:有 $n$ 个数,每个都不超过 $m$.一个三元组 $(a,b,c)$ 是合法的当且仅当 $a=b=c$ 或者 $a+1=b=c-1$.每个数只能用一次.问最多能 ...