#include const double eps=1.0e-9; using namespace std; using pi=pair; using pdpi=pair; int main(){ int x,y; cin >> x >> y; x--;y--; int rd=x*600+y; int n; cin >> n; vector sx(n),sy(n),sv(n); double dp[393939][16]; for(int i=0;i<393939;i++){ for(int j=0;j<16;j++){ dp[i][j]=1.0e9; } } double len[32]; for(int i=1;i<32;i++){len[i]=1000.0/((double)i);} priority_queue,greater> pq; for(int i=0;i> sx[i] >> sy[i] >> sv[i]; sx[i]--;sy[i]--; if(i){ dp[sx[i]*600+sy[i]][sv[i]]=0.0; pq.push({0.0,{sx[i]*600+sy[i],sv[i]}}); } else{ dp[sx[i]*600+sy[i]][7+sv[i]]=0.0; pq.push({0.0,{sx[i]*600+sy[i],7+sv[i]}}); } } while(!pq.empty()){ pdpi od=pq.top();pq.pop(); int vp=od.second.first; int vt=od.second.second; if(dp[vp][vt]=8){ printf("%.12lf\n",od.first); return 0; } vector kh; if(vp%600!=0){kh.push_back(vp-1);} if(vp%600!=599){kh.push_back(vp+1);} if((vp-600)>=0){kh.push_back(vp-600);} if((vp+600)<360000){kh.push_back(vp+600);} if(vt<=7){ for(auto &nx : kh){ if(dp[nx][vt]>od.first+len[vt]){ dp[nx][vt]=od.first+len[vt]; pq.push({od.first+len[vt],{nx,vt}}); } for(int i=8;i<=14;i++){ if(i-7>=vt){continue;} if(dp[nx][i]>od.first+eps){continue;} int nv=7+max(vt,i-7); if(dp[nx][i]+len[i-7]+eps>=od.first){ double reml=max(0.0,1000.0-(od.first-dp[nx][i])*(i-7.0)); double kgl=reml*vt/(i+vt-7.0); double kgt=reml/(i+vt-7.0); //cout << reml << ' ' << kgl << ',' << kgt << '\n'; int tg=vp; double nt=od.first+2.0*kgt; if(dp[tg][nv]>nt){ dp[tg][nv]=nt; pq.push({nt,{tg,nv}}); } tg=nx; nt=od.first+kgt+(1000.0-kgl)/(nv-7.0); if(dp[tg][nv]>nt){ dp[tg][nv]=nt; pq.push({nt,{tg,nv}}); } } } } } else{ for(auto &nx : kh){ if(dp[nx][vt]>od.first+len[vt-7]){ dp[nx][vt]=od.first+len[vt-7]; pq.push({od.first+len[vt-7],{nx,vt}}); } for(int i=1;i<=7;i++){ if(vt-7>=i){continue;} if(dp[nx][i]>od.first+eps){continue;} int nv=7+max(vt-7,i); if(dp[nx][i]+len[i]+eps>=od.first){ double reml=max(0.0,1000.0-(od.first-dp[nx][i])*((double)i)); double kgl=reml*(vt-7.0)/(i+vt-7.0); double kgt=reml/(i+vt-7.0); //cout << reml << ' ' << kgl << '@' << kgt << '\n'; int tg=vp; double nt=od.first+2.0*kgt; if(dp[tg][nv]>nt){ dp[tg][nv]=nt; pq.push({nt,{tg,nv}}); } tg=nx; nt=od.first+kgt+(1000.0-kgl)/(nv-7.0); if(dp[tg][nv]>nt){ dp[tg][nv]=nt; pq.push({nt,{tg,nv}}); } } } } } } return 0; }