#include <set>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
int m, n;
int v[22][22];
char t[22][22];
int main()
{
while (~scanf("%d%d", &m, &n))
{
int x, y;
scanf("%d%d", &x, &y);
memset(v, 0, sizeof(v));
for (int i = 0; i < m; i++)
{
scanf("%s", t[i]);
}
while (1)
{
if (x < 0 || y < 0 || x == m || y == n)
{
printf("YES\n");
break;
}
if (v[x][y])
{
printf("NO\n");
break;
}
v[x][y] = 1;
if (t[x][y] == 'N') x--;
else if (t[x][y] == 'S') x++;
else if (t[x][y] == 'W') y--;
else if (t[x][y] == 'E') y++;
}
}
return 0;
}
NOJ [1257] Get Lost
模拟题,按照当前所站的位置的NSWE来走。
当走到地图外面去了,YES。
当走到以前走过的格子,NO。
出题代码: