Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- using namespace std;
- #define MAX 1030
- char mapa[MAX][MAX];
- int n, m;
- int dx[4] = {1,-1,0,0};
- int dy[4] = {0,0,-1,1};
- bool inGrid(int i, int j) {
- if (i < 0 || i >= n || j < 0 || j >= m) {
- return false;
- }
- return (mapa[i][j] == '.');
- }
- void backtracking(int i, int j) {
- mapa[i][j] = 'o';
- int x;
- for (x = 0; x < 4; x++) {
- if (inGrid(i + dx[x], j + dy[x])) {
- backtracking(i + dx[x], j + dy[x]);
- }
- }
- }
- int main()
- {
- int i,j;
- scanf("%d %d",&n,&m);
- for (i = 0; i < n; i++) {
- scanf("%s",&mapa[i]);
- getchar();
- }
- int ans=0;
- for (i = 0; i < n; i++) {
- for (j = 0; j < m; j++) {
- if (mapa[i][j]=='.') {
- ans++;
- backtracking(i, j);
- }
- }
- }
- printf("%d\n",ans);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement