/* Survive. Live. Win. Conquer.*/ #include using namespace std; typedef long long LL ; #define get(a) for( int i = 0; i < n; i++) sf("%d", &a[i]) ; #define bug printf("TRUST\n"); #define pf printf #define sf scanf #define lp(i, n) for(int i = 0; i < n; i++) #define rlp(n, i) for(int i = n - 1; i >= 0; i--) #define bye vector #define pb push_back #define r0 return 0 #define ff first #define ss second #define mp make_pair #define pii pair #define sz(a) ((int)a.size()) #define set0(a) memset ((a), 0 , sizeof(a)) #define set1(a) memset((a),-1,sizeof (a)) #define si(a) scanf("%d" , &a) #define sl(a) scanf("%lld" , &a) #define sii(a,b) scanf("%d %d" , &a , &b) #define sll(a,b) scanf("%lld %lld" , &a , &b) #define slll(a,b,c) scanf("%lld %lld %lld" , &a , &b, &c) #define FOR(i,a,b) for(LL i = (a) ; i <= (b) ; i++) #define mod 1000000007 #define nod 200003 void func(void) { freopen("input.c","r",stdin); freopen("output.c","w",stdout); } string a[25]; map , pair > mm; int dx[] = {0, 0, -1, 1}; int dy[] = {1, -1, 0, 0}; LL win = 0, total = 0; LL n, m; LL vis[25][25]; void dfs(int x, int y){ int fg = 0; vis[x][y] = 1; pair p = mm[{x, y}]; if(p.ff != 0 and p.ss != 0){ x = max(0LL, p.ff); y = max(0LL, p.ss); } // cout << p.ff << " $$$$ " << p.ss << endl; //cout << x << " " << y << endl; if(a[x][y] == '%'){ win++; total++; return; } if(a[x][y] == '*'){ total++; return; } for(int i = 0 ; i < 4; i++){ int xx = x + dx[i]; int yy = y + dy[i]; if(xx >= 0 and xx < n and yy >= 0 and yy < m and a[xx][yy] != '#' and !vis[xx][yy]){ dfs(xx, yy); fg = 1; } } if(fg == 0){ total++; } } //LL n, m; int main(){ // ios_base::sync_with_stdio(0); cin.tie(0); system("COLOR F0"); LL q, i,j = 0, temp, t, k, ans = 0, sum = 0, x, y, z, cnt = 0, fg = 0, mx = 0, mx1 = 0, mn = 8000000000000000000, mn1 = 8000000000000000000; cin >> n >> m >> k; for(int i = 0; i < n; i++){ cin >> a[i]; for(int j = 0; j < m; j++){ if(a[i][j] == 'A'){ x = i; y = j; } } } for(int i = 0; i < k; i++){ LL x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; if(x2 == 0 and y2 == 0){ x2 = -1; y2 = -1; } x1--, y1--, x2--, y2--; mm[{x1, y1}] = {x2, y2}; } // cout << x << " " << y << endl; dfs(x, y); //bug; cout << fixed << setprecision(10) << (double) win / total * 1.0 << endl; }