#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, k = 0;
cin >> n >> m;
vector <vector <long double> > v(n, vector <long double> (m));
int cz = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
char a;
cin >> a;
if (a == 'O') {
v[i][j] = 1;
k++;
cz += (i + j) % 2;
cz %= 2;
}
}
}
vector <vector <char> > kon(n, vector <char> (m));
if (k == 1) {
pair <int, int> xd;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> kon[i][j];
if (kon[i][j] == 'O') {
xd = {i, j};
if ((i + j) % 2 != cz) {
cout << "0\n";
return 0;
}
}
}
}
int t = 10000;
while (t--) {
vector <vector <long double> > temp(n, vector <long double> (m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int ls = 0;
if (i != 0)
ls++;
if (i != n-1)
ls++;
if (j != 0)
ls++;
if (j != m-1)
ls++;
if (i != 0)
temp[i-1][j] += v[i][j] / ls;
if (i != n-1)
temp[i+1][j] += v[i][j] / ls;
if (j != 0)
temp[i][j-1] += v[i][j] / ls;
if (j != m-1)
temp[i][j+1] += v[i][j] / ls;
}
}
v = temp;
}
cout << fixed << setprecision(15) << v[xd.first][xd.second] << "\n";
return 0;
}
int temp = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> kon[i][j];
if (kon[i][j] == 'O') {
temp += (i+j) % 2;
temp %= 2;
}
}
}
if (temp != cz)
cout << "0\n";
return 0;
}
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 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, k = 0; cin >> n >> m; vector <vector <long double> > v(n, vector <long double> (m)); int cz = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { char a; cin >> a; if (a == 'O') { v[i][j] = 1; k++; cz += (i + j) % 2; cz %= 2; } } } vector <vector <char> > kon(n, vector <char> (m)); if (k == 1) { pair <int, int> xd; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> kon[i][j]; if (kon[i][j] == 'O') { xd = {i, j}; if ((i + j) % 2 != cz) { cout << "0\n"; return 0; } } } } int t = 10000; while (t--) { vector <vector <long double> > temp(n, vector <long double> (m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int ls = 0; if (i != 0) ls++; if (i != n-1) ls++; if (j != 0) ls++; if (j != m-1) ls++; if (i != 0) temp[i-1][j] += v[i][j] / ls; if (i != n-1) temp[i+1][j] += v[i][j] / ls; if (j != 0) temp[i][j-1] += v[i][j] / ls; if (j != m-1) temp[i][j+1] += v[i][j] / ls; } } v = temp; } cout << fixed << setprecision(15) << v[xd.first][xd.second] << "\n"; return 0; } int temp = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> kon[i][j]; if (kon[i][j] == 'O') { temp += (i+j) % 2; temp %= 2; } } } if (temp != cz) cout << "0\n"; return 0; } |
English