#include <iostream> double Newton(unsigned int n, unsigned int k) { double result = 1; for (unsigned int i = 1; i <= k; i++) result = result * (n - i + 1) / i; return (double) result; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n, m; std::cin >> n >> m; int wh_total = 0, bl_total = 0; int wh1 = 0, bl1 = 0; for (int i = 0; i < n; i++) { bool is_wh = (i % 2) == 1; for (int j = 0; j < m; j++) { is_wh = !is_wh; if (is_wh) wh_total++; else bl_total++; char c; std::cin >> c; if (c != 'O') continue; if (is_wh) wh1++; else bl1++; } } int wh2 = 0, bl2 = 0; for (int i = 0; i < n; i++) { bool is_wh = (i % 2) == 1; for (int j = 0; j < m; j++) { is_wh = !is_wh; char c; std::cin >> c; if (c != 'O') continue; if (is_wh) wh2++; else bl2++; } } if (wh1 != wh2) { std::cout << 0; return 0; } std::cout << (1 / (Newton(wh_total, wh1) * Newton(bl_total, bl1))); 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 | #include <iostream> double Newton(unsigned int n, unsigned int k) { double result = 1; for (unsigned int i = 1; i <= k; i++) result = result * (n - i + 1) / i; return (double) result; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n, m; std::cin >> n >> m; int wh_total = 0, bl_total = 0; int wh1 = 0, bl1 = 0; for (int i = 0; i < n; i++) { bool is_wh = (i % 2) == 1; for (int j = 0; j < m; j++) { is_wh = !is_wh; if (is_wh) wh_total++; else bl_total++; char c; std::cin >> c; if (c != 'O') continue; if (is_wh) wh1++; else bl1++; } } int wh2 = 0, bl2 = 0; for (int i = 0; i < n; i++) { bool is_wh = (i % 2) == 1; for (int j = 0; j < m; j++) { is_wh = !is_wh; char c; std::cin >> c; if (c != 'O') continue; if (is_wh) wh2++; else bl2++; } } if (wh1 != wh2) { std::cout << 0; return 0; } std::cout << (1 / (Newton(wh_total, wh1) * Newton(bl_total, bl1))); return 0; } |