西工大 僵尸来了

#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;
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值