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 126 127 128 129 130 131 132 133 134 135
| #include "iostream" #include "algorithm" #include "cstring" #include "cstdio" #include "cmath" #include "vector" #include "map" #include "set" #include "queue" #include "cassert" #include "numeric" using namespace std; #define MAXN 10036
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedef long long ll; const int X[] = { -1,1,0,0 }; const int Y[] = { 0,0,-1,1 }; int n , m;
char M[MAXN][22]; double p[5]; int gid( int x , int y ) { return ( x - 1 ) * m + y; }
struct vec { int l , r; double A[62]; double val; vec( ) : val(0) { mem( A ); } void ini( int L , int R ) { l = max( L , 1 ) , r = min( R , n * m ); } double& operator [] ( int x ) { assert( x >= l && x <= r ); return A[x - l]; } void gt( int L , int R ) { L = max( L , 1 ) , R = min( R , n * m ); double a[62]; mem( a ); rep( i , L , R ) if( i <= r ) a[i - L] = A[i - l]; memcpy( A , a , sizeof a ); l = L , r = R; } vec operator * ( double t ) { vec as; as.ini( l , r ); rep( i , l , r ) as[i] = A[i - l] * t; as.val = val * t; return as; } void operator -= ( vec t ) { rep( i , max( t.l , l ) , min( t.r , r ) ) A[i - l] -= t[i]; val -= t.val; } } A[MAXN * 60] ;
bool iT[MAXN * 60];
void solve() { cin >> m >> n; rep( i , 0 , 3 ) { int qwq; scanf("%d",&qwq); p[i] = qwq * 1. / 100; } rep( i , 1 , n ) { scanf("%s",M[i] + 1); } int tt = 0; rep( j , 1 , m ) if( M[1][j] == '.' ) ++ tt; rep( i , 1 , n ) rep( j , 1 , m ) { int dx = gid( i , j ); iT[dx] = M[i][j] == 'T'; A[dx].ini( dx - m , dx + 2 * m ); if( M[i][j] == 'X' ) { A[dx][dx] = 1 , A[dx].val = 0; } else { double c = 1; rep( d , 0 , 3 ) { int x = i + X[d] , y = j + Y[d]; if( M[x][y] == 'X' || x < 1 || y < 1 || x > n || y > m ) c -= p[d]; else if( M[x][y] == '.' ) A[dx][gid( x , y )] = -p[d ^ 1]; } if( M[i][j] == 'T' ) c = 1; A[dx][dx] = c; A[dx].val = 0; if( i == 1 && M[i][j] == '.' ) A[dx].val += 1. / tt; } } rep( i , 1 , n * m ) { if( !A[i][i] ) { rep( j , i + 1 , min( i + m , n * m ) ) if( A[j][i] != 0 ) { swap( A[j] , A[i] ); A[j].gt( A[i].l , A[i].r ); } } if( !A[i][i] ) continue; rep( j , i + 1 , min( i + m , n * m ) ) if( A[j][i] != 0 ) { double k = A[j][i] / A[i][i]; A[j] -= A[i] * k; } } vector<double> as; per( i , n * m , 1 ) { rep( j , i + 1 , A[i].r ) if( A[i][j] ) { A[i].val -= A[j].val * A[i][j]; A[i][j] = 0; } A[i].val /= A[i][i]; if( iT[i] ) as.pb( A[i].val ); } reverse( all( as ) ); double s = accumulate( all( as ) , 0. ); for( auto t : as ) { printf("%.7lf\n",t / s); } }
signed main() {
solve(); }
|