#include <bits/stdc++.h> using namespace std; int main() { int n, m, t; while (cin >> n >> m >> t) { vector<vector<char>> mat(n, vector<char>(m)); vector<vector<int>> visited(n, vector<int>(m, 0)); vector<pair<int, int>> dirs = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; int sr = -1, sc = -1; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> mat[i][j]; if (mat[i][j] == 'S') { sr = i, sc = j; } } } auto bfs = [&](int i, int j) -> bool { queue<pair<int, int>> q1, q2; q1.push({i, j}); visited[i][j] = 1; while (t != 0 && !q1.empty()) { int sx = q1.front().first; int sy = q1.front().second; q1.pop(); for (auto dir : dirs) { if (sx+dir.first < 0 || sx+dir.first >= n || sy+dir.second < 0 || sy+dir.second >= m || visited[sx+dir.first][sy+dir.second] || mat[sx+dir.first][sy+dir.second] == '#') { continue; } if (mat[sx+dir.first][sy+dir.second] == 'F') return true; q2.push({sx+dir.first, sy+dir.second}); visited[sx+dir.first][sy+dir.second] = 1; } if (q1.empty()) { t--; q1.swap(q2); } } return false; }; if (bfs(sr, sc)) { cout << "Happy\n"; } else { cout << "Cry\n"; } } } |
Double click to view unformatted code.