1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <iostream>
#include <iomanip>

using namespace std;

const int MAX_N = 10;

 int n,m;

long double tab1[MAX_N][MAX_N];
long double tab2[MAX_N][MAX_N];

pair<int, int> grid[4] = {{1, 0},{-1, 0},{0, 1},{0, -1}};

bool tab1_is_current = true;

void calc_round(){
	if(tab1_is_current){
		for(int y = 1; y <= n; y++ ){
			for(int x = 1; x <= m; x++){
				tab2[y][x] = 0;
				for(int i = 0; i < 4; i++){
					tab2[y][x] += tab1[y + grid[i].first][x + grid[i].second];
				}
			}
		}

		tab1_is_current = false;
	}
	else{
		for(int y = 1; y <= n; y++ ){
			for(int x = 1; x <= m; x++){
				tab1[y][x] = 0;
				for(int i = 0; i < 4; i++){
					tab1[y][x] += tab2[y + grid[i].first][x + grid[i].second];
				}
			}
		}

		tab1_is_current = true;
	}
}

int main()
{


    cin>>n>>m;

    string wejscie;

    for(int i = 0; i < n; i++){

		cin>>wejscie;

		for(int x = 0; x < m; x++){
			if(wejscie[x] == 'O') tab1[i + 1][x + 1] = 1;
		}
    }

    long double wynik = 1;
	long double current_szansa;

	long double suma = 0;

	for(int j = 0; j < 800; j++){
		suma = 0;

    for(int i = 0; i < 10; i++) {

		calc_round();

		}

		for(int i = 0; i < n; i++){



		for(int x = 0; x < m; x++){
			suma+= tab1[i + 1][x + 1];
		}
    }


     for(int i = 0; i < n; i++){


		for(int x = 0; x < m; x++){

			current_szansa = (long double)(tab1[i + 1][x + 1])/(long double)(suma);
			tab1[i + 1][x+ 1] = (long double) (current_szansa * 100);
		}
    }


}

suma = 0;
for(int i = 0; i < n; i++){



		for(int x = 0; x < m; x++){
			suma+= tab1[i + 1][x + 1];
		}
    }

     for(int i = 0; i < n; i++){

		cin>>wejscie;

		for(int x = 0; x < m; x++){
			if(wejscie[x] == 'O'){
				current_szansa = (long double)(tab1[i + 1][x + 1])/(long double)(suma);
				wynik*= current_szansa;
			}
		}
    }


	cout<<setprecision(13)<<fixed<<current_szansa;


    return 0;
}