// 开局见五子棋示例。先找能连五的点,再堵对手的一步胜;其余情况靠近中心。 #include #include #include constexpr int size = 15; int board[size][size]{}; // board[y][x]:0 为空,1 为黑,2 为白 bool inBoard(int x, int y) { return x >= 0 && x < size && y >= 0 && y < size; } bool wouldWin(int x, int y, int color) { constexpr int directions[][2] = {{1, 0}, {0, 1}, {1, 1}, {1, -1}}; for (const auto& direction : directions) { int count = 1; // 假设在当前空点落下一子 for (int sign : {-1, 1}) { int dx = direction[0] * sign, dy = direction[1] * sign; int col = x + dx, row = y + dy; while (inBoard(col, row) && board[row][col] == color) { ++count; col += dx; row += dy; } } if (count >= 5) return true; } return false; } int main() { int moves; if (std::scanf("%d", &moves) != 1 || moves < 0 || moves >= size * size) return 1; for (int ply = 0; ply < moves; ++ply) { char column; int row; if (std::scanf(" %c%d", &column, &row) != 2) return 1; int x = column - 'A', y = row - 1; if (!inBoard(x, y) || board[y][x] != 0) return 1; board[y][x] = 1 + ply % 2; } int color = 1 + moves % 2; int bestScore = -100, bestX = -1, bestY = -1; for (int y = 0; y < size; ++y) { for (int x = 0; x < size; ++x) { if (board[y][x] != 0) continue; int score = -std::abs(x - 7) - std::abs(y - 7); if (wouldWin(x, y, color)) score += 200; else if (wouldWin(x, y, 3 - color)) score += 100; if (score > bestScore) { bestScore = score; bestX = x; bestY = y; } } } if (bestX < 0) return 1; std::printf("%c%d\n", 'A' + bestX, bestY + 1); return 0; }