Problem Description:
桐老爷和UGO终于来到了名为“是男人就上一百层的塔”的下面,听说大祭司在第100层沉睡。为了题目需要,我把这个塔的层数随机打乱,层数的话大家就忘了前面的100吧,用n*m的一个矩阵来代替。前面提到大祭司在沉睡,所以桐人和尤吉欧希望赶快到达大祭司面前杠正面,但是有些层有整合骑士看守。只有在桐人或者UGO有“Enhance armament”(武装支配术)才可以打败,否则无法从这里通过。他们只可以从当前位置上下左右移动,不能斜着走。从一层走到另一层耗费1个时间单位,打败整合骑士不耗时间但是会消耗一个武装支配术。问:他们最快多久可以到达大祭司面前。
Input:
输入的第一行包含三个整数:M,N,T。M,N代表M行N列的地图,T代表桐人与尤吉欧武装支配术之和。0 < M,N < 200,0 ≤ T < 10 注:“Enhance armament”无法回复。后面是M行N列的地图,其中@代表桐人和尤吉欧,+代表大祭司。*代表可以直接通过的层,#代表有整合骑士的层。
Output:
输出包含一个整数R,代表桐人和尤吉欧来到大祭司面前最少需要花费的时间。如果桐尤无法追来到大祭司面前,则输出-1。
Sample Input:
4 4 1
#@##
**##
###+
****
4 4 2
#@##
**##
###+
****
Sample Output:
6
4
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<set>
#include<queue>
#include<cstring>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
struct node
{
int x;
int y;
int time;///时间
int t;///技能
};
node start,end;
int d[][]={ -,, ,, ,-, , };///上下左右
char a[][];
bool vis[][][];
queue<node>que;
int n,m,t,ans;
void bfs()
{
memset(vis,false,sizeof(vis));
while(!que.empty()) que.pop();
vis[start.x][start.y][start.t]=true;
que.push(start);
while(!que.empty())
{
node now=que.front();
que.pop();
if(a[now.x][now.y]=='+')///遇到boss
{
ans=now.time;
break;
}
for(int i=;i<;i++)
{
int xx=now.x+d[i][];
int yy=now.y+d[i][];
int time=now.time+;///无论有没有怪,时间都要加1
if(xx>= && xx<n && yy>= && yy<m)///不越界的地方里
{
if( (a[xx][yy]=='*' || a[xx][yy]=='+')&& !vis[xx][yy][now.t])///没有怪,大祭司也要加进去
{
vis[xx][yy][now.t]=true;
que.push( {xx,yy,time,now.t} );///技能数不变
}
if(a[xx][yy]=='#' && now.t> && !vis[xx][yy][now.t-] )///有怪,技能数要>1
{
vis[xx][yy][now.t-]=true;
que.push( {xx,yy,time,now.t-});///压入队列技能数要-1
}
}
}
}
}
int main()
{
while(scanf("%d%d%d",&n,&m,&t)!=EOF)
{
ans=-;
for(int i=;i<n;i++)
{
scanf("%s",a[i]);
}
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
if(a[i][j]=='@')
{
start.x=i;
start.y=j;
start.time=;
start.t=t;
}
}
bfs();
printf("%d\n",ans);
}
return ;
}