2013年8月11日

UVa 260 - Il Gioco dell'X

#include <cstdio>
#include <cstring>

const int dr[6] = {-1, -1, 0, 0, 1, 1};
const int dc[6] = {-1, 0, -1, 1, 0, 1};

int N;
char map[201][201];
bool visited[201][201], wWin;

void find(int r, int c) {
  if (r < 0 || r >= N || c < 0 || c >= N) {
    return;
  }
  if (wWin || visited[r][c]) {
    return;
  }
  visited[r][c] = true;
  if (map[r][c] != 'w') {
    return;
  }
  if (c == N - 1) {
    wWin = true;
    return;
  }
  for (int i = 0; i < 6; i++) {
    find(r + dr[i], c + dc[i]);
  }
}

int main() {
  int C = 1;
  while (scanf("%d", &N) && N) {
    for (int r = 0; r < N; r++) {
      scanf("%s", map[r]);
    }
    wWin = false;
    for (int r = 0; r < N && !wWin; r++) {
      memset(visited, 0, sizeof(visited));
      find(r, 0);
    }
    printf("%d %s\n", C++, wWin ? "W" : "B");
  }
  return 0;
}

沒有留言:

張貼留言