#include "iostream" #include "climits" #include "list" #include "queue" #include "stack" #include "set" #include "functional" #include "algorithm" #include "string" #include "map" #include "unordered_map" #include "unordered_set" #include "iomanip" #include "cmath" #include "random" #include "bitset" #include "cstdio" #include "numeric" #include "cassert" #include "ctime" using namespace std; constexpr long long int MOD = 1000000007; //constexpr int MOD = 1000000007; //constexpr int MOD = 998244353; //constexpr long long int MOD = 998244353; constexpr double EPS = 1e-8; //int N, M, K, T, H, W, L, R; long long int N, M, K, T, H, W, L, R; struct Node { int y, x, v, ok; long double cost; Node(int y, int x, int v, int ok,long double cost) :y(y), x(x), v(v), ok(ok),cost(cost) { } bool operator<(const Node& n)const { return cost > n.cost; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); H = 600, W = 600; int gy, gx; cin >> gy >> gx; gy--, gx--; cin >> N; vector>>>dis(H, vector>>(W, vector>(8, vector(2, MOD)))); priority_queuePQ; int exist[8] = {}; for (int i = 0; i < N; i++) { int y, x, v; cin >> y >> x >> v; exist[v] = 1; y--, x--; if (i) { dis[y][x][v][0] = 0; PQ.push(Node(y, x, v, 0, 0)); } else { dis[y][x][v][1] = 0; PQ.push(Node(y, x, v, 1, 0)); } } int dir[] = { 1,0,-1,0,1 }; while (!PQ.empty()) { auto box = PQ.top(); if (box.cost < 1300) { cout << box.y << " " << box.x << " " << box.v << " " << box.ok << " " << box.cost << endl; } PQ.pop(); if (box.ok) { for (int i = 1; i < 8; i++) { if (!exist[i])continue; if (dis[box.y][box.x][i][1] > dis[box.y][box.x][i][0] && dis[box.y][box.x][i][0] > box.cost) { dis[box.y][box.x][i][1] = dis[box.y][box.x][i][0]; PQ.push(Node(box.y, box.x, i, 1, dis[box.y][box.x][i][0])); } } } else { for (int i = 1; i < 8; i++) { if (!exist[i])continue; if (dis[box.y][box.x][i][1] > box.cost) { long double d = box.cost + (dis[box.y][box.x][i][1] - box.cost) * i / (i + box.v) * 2; if (dis[box.y][box.x][box.v][1] > d) { PQ.push(Node(box.y, box.x, box.v, 1, d)); } } if (dis[box.y][box.x][i][1] <= box.cost) { if (dis[box.y][box.x][box.v][1] > box.cost) { PQ.push(Node(box.y, box.x, box.v, 1, box.cost)); } } } } for (int d = 0; d < 4; d++) { int ny = box.y + dir[d]; int nx = box.x + dir[d + 1]; if (ny < 0 || nx < 0 || ny >= H || nx >= W)continue; if (dis[ny][nx][box.v][box.ok] > box.cost + ((long double)1000) / box.v) { dis[ny][nx][box.v][box.ok] = box.cost + ((long double)1000) / box.v; PQ.push(Node(ny, nx, box.v, box.ok, box.cost + ((long double)1000) / box.v)); } } } long double ans = MOD; for (int i = 1; i <= 7; i++) { ans = min(ans, dis[gy][gx][i][1]); } cout << fixed << setprecision(20) << ans << endl; }