#include <algorithm>
#include <limits>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int wys, szer;
vector<string> pp, pk;
int liczCz(vector<string> &p)
{
int wyn=0;
for (int y=0; y<wys; ++y)
for (int x=0; x<szer; ++x)
if ((x+y)%2 && p[y][x]=='O')
++wyn;
return wyn;
}
int main()
{
cin>>wys>>szer;
for (int i=0; i<wys; ++i)
{
string s;
cin>>s;
pp.push_back(s);
}
for (int i=0; i<wys; ++i)
{
string s;
cin>>s;
pk.push_back(s);
}
if (liczCz(pp)!=liczCz(pk))
{
cout<<0<<endl;
return 0;
}
vector<vector<double>> p(wys, vector<double>(szer, 0));
for (int y=0; y<wys; ++y)
for (int x=0; x<szer; ++x)
if (pp[y][x]=='O')
p[y][x]=1;
for (int i=0; i<1000; ++i)
{
/*
cout<<i<<"===========\n";
for (int y=0; y<wys; ++y)
{
for (double d : p[y])
cout<<d<<'\t';
cout<<endl;
}
cout<<endl;
*/
vector<vector<double>> q(wys, vector<double>(szer, 0));
for (int y=0; y<wys; ++y)
for (int x=0; x<szer; ++x)
{
int lr=0;
if (0<x)
++lr;
if (x+1<szer)
++lr;
if (0<y)
++lr;
if (y+1<wys)
++lr;
double pr=p[y][x]/lr;
if (0<x)
q[y][x-1]+=pr;
if (x+1<szer)
q[y][x+1]+=pr;
if (0<y)
q[y-1][x]+=pr;
if (y+1<wys)
q[y+1][x]+=pr;
}
p.swap(q);
}
cout.precision(15);
for (int y=0; y<wys; ++y)
for (int x=0; x<szer; ++x)
if (pk[y][x]=='O')
cout<<p[y][x]<<endl;
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | #include <algorithm> #include <limits> #include <map> #include <set> #include <sstream> #include <string> #include <vector> #include <iostream> using namespace std; int wys, szer; vector<string> pp, pk; int liczCz(vector<string> &p) { int wyn=0; for (int y=0; y<wys; ++y) for (int x=0; x<szer; ++x) if ((x+y)%2 && p[y][x]=='O') ++wyn; return wyn; } int main() { cin>>wys>>szer; for (int i=0; i<wys; ++i) { string s; cin>>s; pp.push_back(s); } for (int i=0; i<wys; ++i) { string s; cin>>s; pk.push_back(s); } if (liczCz(pp)!=liczCz(pk)) { cout<<0<<endl; return 0; } vector<vector<double>> p(wys, vector<double>(szer, 0)); for (int y=0; y<wys; ++y) for (int x=0; x<szer; ++x) if (pp[y][x]=='O') p[y][x]=1; for (int i=0; i<1000; ++i) { /* cout<<i<<"===========\n"; for (int y=0; y<wys; ++y) { for (double d : p[y]) cout<<d<<'\t'; cout<<endl; } cout<<endl; */ vector<vector<double>> q(wys, vector<double>(szer, 0)); for (int y=0; y<wys; ++y) for (int x=0; x<szer; ++x) { int lr=0; if (0<x) ++lr; if (x+1<szer) ++lr; if (0<y) ++lr; if (y+1<wys) ++lr; double pr=p[y][x]/lr; if (0<x) q[y][x-1]+=pr; if (x+1<szer) q[y][x+1]+=pr; if (0<y) q[y-1][x]+=pr; if (y+1<wys) q[y+1][x]+=pr; } p.swap(q); } cout.precision(15); for (int y=0; y<wys; ++y) for (int x=0; x<szer; ++x) if (pk[y][x]=='O') cout<<p[y][x]<<endl; return 0; } |
English