using System; using System.IO; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; namespace No659 { public class Program { void Solve(StreamScanner ss, StreamWriter sw) { //--------------------------------- var H = ss.Next(Int); var W = ss.Next(Int); var T = ss.Next(Int); var Sy = ss.Next(Int); var Sx = ss.Next(Int); var Gy = ss.Next(Int); var Gx = ss.Next(Int); var B = ss.Next(String, H); Func isInside = (x, y) => 0 <= x && x < W && 0 <= y && y < H; int[] dx = { 0, 1, 0, -1 }; int[] dy = { 1, 0, -1, 0 }; var dl = 4; var random = new Random(); var walkEnd = (T - 100) % 100 + 100; Func dfs = null; dfs = (x, y, t) => { if (t == walkEnd) return x == Gx && y == Gy; var xs = new List(); var ys = new List(); for (var i = 0; i < dl; i++) { var cx = x + dx[i]; var cy = y + dy[i]; if (isInside(cx, cy) && B[cy][cx] == '.') { xs.Add(cx); ys.Add(cy); } } var r = random.Next(xs.Count); var nx = xs[r]; var ny = ys[r]; return dfs(nx, ny, t + 1); }; var goalCount = 0; var trialCount = 100000d; for (var i = 0; i < trialCount; i++) { if (dfs(Sx, Sy, 0)) goalCount++; } sw.WriteLine(goalCount / trialCount); //--------------------------------- } static void Main() { var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput())); var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false}; new Program().Solve(ss, sw); sw.Flush(); } static readonly Func String = s => s; static readonly Func Int = int.Parse; static readonly Func Long = long.Parse; static readonly Func Double = double.Parse; } public class StreamScanner { static readonly char[] Sep = {' '}; readonly Queue buffer = new Queue(); readonly TextReader textReader; public StreamScanner(TextReader textReader) { this.textReader = textReader; } [SuppressMessage("ReSharper", "PossibleNullReferenceException")] public T Next(Func parser) { if (buffer.Count != 0) return parser(buffer.Dequeue()); var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries); foreach (var nextString in nextStrings) buffer.Enqueue(nextString); return Next(parser); } public T[] Next(Func parser, int x) { var ret = new T[x]; for (var i = 0; i < x; ++i) ret[i] = Next(parser); return ret; } public T[][] Next(Func parser, int x, int y) { var ret = new T[y][]; for (var i = 0; i < y; ++i) ret[i] = Next(parser, x); return ret; } } }