#include<iostream>
#include<stdio.h>
#include<queue>
using namespace std;
int used[200][200];
char mapp[200][200];
int step[200][200];
struct node
{
int x;
int y;
int t;
};
int m,n,tq;
int walk[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};
queue<struct node> q1;
int canmove(struct node d,int i)
{
struct node nd;
nd.x = d.x + walk[i][0];
nd.y = d.y + walk[i][1];
nd.t = d.t;
if(nd.x >= m || nd.y >= n || nd.x < 0 || nd.y < 0)
return 0;
if(mapp[nd.x][nd.y] == 'w')
{
nd.t --;
if(nd.t <= 0)
return 0;
}
if(used[nd.x][nd.y] == 1)
return 0;
return 1;
}
struct node moveto(struct node d,int i)
{
struct node nd;
nd.x = d.x + walk[i][0];
nd.y = d.y + walk[i][1];
nd.t = d.t;
used[nd.x][nd.y] = 1;
if(mapp[nd.x][nd.y] == 'w')
nd.t = nd.t - 1;
return nd;
}
void dps()
{
while(!q1.empty())
{
struct node d = q1.front();
q1.pop();
used[d.x][d.y] = 1;
struct node nd;
if(mapp[d.x][d.y] == '+')
{
printf("%d\n",step[d.x][d.y]);
return;
}
else
{
for(int i = 0; i <4; i ++)
{
if(canmove(d,i))
{
nd = moveto(d,i);
q1.push(nd);
step[nd.x][nd.y] = step[d.x][d.y] + 1;
}
}
}
}
printf("-1\n");
}
int main()
{
scanf("%d%d%d",&m,&n,&tq);
struct node d;
d.t = tq;
scanf("\n");
for(int i = 0; i < m; i ++)
{
for(int j = 0; j < n; j ++)
{
scanf("%c",&mapp[i][j]);
if(mapp[i][j] == '!')
{
d.x = i;
d.y = j;
}
}
if(i < m - 1)
scanf("\n");
}
used[d.x][d.y] = 1;
step[d.x][d.y] = 0;
q1.push(d);
dps();
return 0;
}
西工大 僵尸来了
最新推荐文章于 2024-10-06 10:17:48 发布