n,m=list(map(int,input().split())) s1=[] for i in range(n): s1.append(list(input())) f=input() s2=[] for i in range(n): s2.append(list(input())) p=0 a=True r=0 for i in range(n): for j in range(m): if s1[i][j]=="O": p+=1 if (i+j)%2: a=not a if s2[i][j]=="O": if (i+j)%2: a=not a if i>0 and s2[i-1][j]==".": r+=1 if j>0 and s2[i][j-1]==".": r+=1 if i<n-1 and s2[i+1][j]==".": r+=1 if j<m-1 and s2[i][j+1]==".": r+=1 w=1 for j in range(p-1): w*=n*m-2-j for j in range(1,p): w//=j w*=2*n*m-n-m if a: print("{:.18f}".format(r/w)) else: print(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 | n,m=list(map(int,input().split())) s1=[] for i in range(n): s1.append(list(input())) f=input() s2=[] for i in range(n): s2.append(list(input())) p=0 a=True r=0 for i in range(n): for j in range(m): if s1[i][j]=="O": p+=1 if (i+j)%2: a=not a if s2[i][j]=="O": if (i+j)%2: a=not a if i>0 and s2[i-1][j]==".": r+=1 if j>0 and s2[i][j-1]==".": r+=1 if i<n-1 and s2[i+1][j]==".": r+=1 if j<m-1 and s2[i][j+1]==".": r+=1 w=1 for j in range(p-1): w*=n*m-2-j for j in range(1,p): w//=j w*=2*n*m-n-m if a: print("{:.18f}".format(r/w)) else: print(0) |