## 题目描述

500年前，Jesse是我国最卓越的剑客。他英俊潇洒，而且机智过人^_^。

## 样例输入

4 4 10............S**P0 0 0

## 样例输出

YES

## 解题思路

#include <stdio.h>#include <string.h>struct note {    int x, s, y;}que[401];int main() {    char map[25][25];    int t, n, m, p, q, vis[25][25];    int next[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};    while (scanf("%d %d %d", &n, &m, &t), n || m || t) {        int tx, ty, head = 1, tail = 1, temp = 0;        memset(vis, 0, sizeof(vis));        for (int i = 1; i <= m; i++) {            getchar();            for (int j = 1; j <= n; j++) {                scanf("%c", &map[i][j]);                if (map[i][j] == 'S') {                    que[tail].x = i;                    que[tail].y = j;                }                if (map[i][j] == 'P') {                    p = i;                    q = j;                }            }        }        vis[que[tail].x][que[tail].y] = 1;        que[tail++].s = 0;        while (head < tail) {            for (int k = 0; k < 4; k++) {                tx = que[head].x + next[k][0];                ty = que[head].y + next[k][1];                 if (tx < 1 || ty < 1 || tx > m || ty > n)                    continue;                if (!vis[tx][ty] && map[tx][ty] != '*') {                    vis[tx][ty] = 1;                    que[tail].x = tx;                    que[tail].y = ty;                    que[tail++].s = que[head].s + 1;                }                if (tx == p && ty == q) {                    temp = 1;                    break;                }            }            if (temp)                break;            head++;        }        if (que[tail - 1].s <= t && temp)            puts("YES");        else puts("NO");    }    return 0;}