#include using namespace std; #define PAD 1.0l struct trys{ short x,y; long double p=1; trys(short a,short b):x(a),y(b),p(PAD) {} trys(pair a, long double p):x(a.first),y(a.second),p(p) {} trys(short a,short b, long double p):x(a),y(b),p(p) {} }; int main() { int n; int m; int k; cin >> n >> m >> k; char lab[n][m]; queueeil; pair st; map,pair>tun; int minu=0; for(int a0 = 0; a0 < n; a0++){ for(int j = 0;j> lab[a0][j]; if(lab[a0][j]=='A'){ eil.push(trys(a0,j)); st=make_pair(a0,j); lab[a0][j]='O'; } minu+=lab[a0][j]=='*'; tun[make_pair(a0,j)]=make_pair(a0,j); } } if(minu==0){ queue>eil; eil.push(st); bool apl[n][m]={}; apl[st.first][st.second]=true; while(!eil.empty()){ pair d = eil.front(); eil.pop(); #define x first #define y second if(lab[d.x][d.y]=='%'){ cout << 1; return 0; } if(d.x>0 and lab[d.x-1][d.y]!='#' and !apl[d.x-1][d.y]){ eil.push(make_pair(d.x-1,d.y)); apl[d.x-1][d.y]=true; } if(d.y>0 and lab[d.x][d.y-1]!='#' and !apl[d.x][d.y-1]){ eil.push(make_pair(d.x,d.y-1)); apl[d.x][d.y-1]=true; } if(d.x+1> i1 >> j1 >> i2 >> j2; i1--,i2--,j1--,j2--; tun[make_pair(i1,j1)]=make_pair(i2,j2); tun[make_pair(i2,j2)]=make_pair(i1,j1); } long double pro = 0; while(!eil.empty()){ trys d = eil.front(); eil.pop(); if(lab[d.x][d.y]=='*') continue; if(lab[d.x][d.y]=='%'){ pro+=d.p; continue; } if(d.p<0.0000001l){ pro+=d.p/2; continue; } vector> tol; if(d.x>0 and lab[d.x-1][d.y]!='#'){ tol.push_back(tun[make_pair(d.x-1,d.y)]); } if(d.y>0 and lab[d.x][d.y-1]!='#'){ tol.push_back(tun[make_pair(d.x,d.y-1)]); } if(d.x+1&p:tol){ eil.push(trys(p,d.p/tol.size())); } } cout<