Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <string>
- #include <set>
- #include <stack>
- #include <queue>
- #include <deque>
- using namespace std;
- /*
- #define TASK "linkedmap"
- int main() {
- #ifdef _DEBUG
- freopen("debug.in", "r", stdin);
- freopen("debug.out", "w", stdout);
- #else
- freopen(TASK".in", "r", stdin);
- freopen(TASK".out", "w", stdout);
- #endif // _DEBUG
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- return 0;
- }
- */
- char a[12][12];
- bool used[12][12];
- int kol = 0, n, m;
- void dfs(int x, int y)
- {
- used[x][y] = true;
- if (a[x][y] == 'F')
- {
- kol++;
- return;
- }
- if (!used[x + 1][y] && a[x + 1][y] == '.' || a[x + 1][y] == 'F')
- dfs(x + 1, y);
- if (!used[x - 1][y] && a[x - 1][y] == '.' || a[x - 1][y] == 'F')
- dfs(x - 1, y);
- if (!used[x][y - 1] && a[x][y - 1] == '.' || a[x][y - 1] == 'F')
- dfs(x, y - 1);
- if (!used[x][y + 1] && a[x][y + 1] == '.' || a[x][y + 1] == 'F')
- dfs(x, y + 1);
- used[x][y] = false;
- return;
- }
- int main()
- {
- #ifdef _DEBUG
- freopen("debug.in", "r", stdin);
- freopen("debug.out", "w", stdout);
- #else
- freopen(TASK".in", "r", stdin);
- freopen(TASK".out", "w", stdout);
- #endif // _DEBUG
- int i, k, c1, c2;
- cin >> n >> m;
- c1 = c2 = 0;
- for (i = 1; i <= n; i++) {
- for (k = 1; k <= m; k++)
- {
- cin >> a[i][k];
- if (a[i][k] == 'S')
- {
- c1 = i;
- c2 = k;
- }
- }
- }
- for (i = 0; i <= 11; i++) {
- for (k = 1; k <= 11; k++)
- {
- if (i == 0 || i == n + 1 || k == 0 || k == m + 1) {
- used[i][k] = true;
- }
- }
- }
- if (c1 != 0)
- dfs(c1, c2);
- cout << kol;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement