eolymp
bolt
Try our new interface for solving problems
Problems

Rock Skipping

Rock Skipping

You are skipping rocks on a lake. To skip a rock, you throw the rock horizontally with its flattest edge down and parallel to the lake, and spin it as it leaves your hand. The rock will skim the surface of the water, and leap back into the air for a distance, then skim again, repeating until it enters the water. The spin on the rock keeps it flat while it flies through the air, and its direction stays relatively constant. The pattern the rock takes as it skips along the lake is quite unusual, due to the imperfect surfaces of the rock and lake. The rock's skips (distances the rock jumps) are on average smaller as the rock gets further away, probably due to resistance against the water and air. However, sometimes the rock will go further than previous skips. Also, when the rock hits one of the many lily pads on the lake, it immediately sinks after sliding over the lily pad. Interestingly enough, the number of times the rock skips appears to be somewhat constant (unless it hits a lily pad). Being the geeky computer scientist that you are, you devise a function determining the probablity that a rock being skipped will avoid all the lily pads. There are two inputs for your function, the lily pad pattern (pads) on the lake in the direction you are throwing, and the maximum distance (\textbf{maxDist}) that the rock will skip after striking the water for the first time. \textbf{pads} will be input as a String. Each character in the String will represent a space of lake, '\textbf{.}' representing open water and '\textbf{X}' representing a lily pad. Assume the lake continues infinitely off to the right of the pattern, repeating the pattern over and over again. So for instance, the pattern "\textbf{.X.X..}" corresponds to the lake \textbf{.X.X...X.X...X.X..}, which extends infinitely to the right. You throw your rock from the left side of the lake across to the right side, and aim it so the rock strikes the first space of lake (the first character in pads, which is always guaranteed to be open water). You should also assume that the rock's horizontal direction does not change (i.e. the rock's horizontal movement is always along the lily pad pattern). \textbf{maxDist} will define how hard you throw the rock. You hypothesize that for the first skip, the maximum distance it could possibly jump is \textbf{maxDist} lake spaces. After each skip, the maximum distance is decreased by one, yielding a maximum distance of \textbf{maxDist} - \textbf{N} spaces for skip \textbf{N} (\textbf{N} starts at \textbf{0}). The rock succumbs to the icy water when N equals maxDist or when the rock hits a lily pad. To account for the erratic skipping patterns, you hypothesize that the rock has an equal chance of skipping any integral distance between \textbf{1} and \textbf{maxDist} - \textbf{N} inclusive for skip \textbf{N} (to simplify the problem, assume the rock always lands in the middle of a space). Your return value should be a probability from \textbf{0} to \textbf{100}, which represents the percentage likelihood that the rock will not hit any lily pads. \InputFile First line contains string \textbf{pads}. It will have between \textbf{1} and \textbf{50} characters, inclusive and will consist only of the characters '\textbf{.}' and '\textbf{X}'. Second line contains \textbf{maxDist}. It will be between \textbf{2} and \textbf{100}, inclusive. \textbf{Ouput} Output single value --- probability from \textbf{0} to \textbf{100}. Your answer will be considered correct if it is within \textbf{10^\{-9\}} of relative or absolute error from the correct answer.
Time limit 1 second
Memory limit 64 MiB
Input example #1
.
100
Output example #1
100
Source Sazanka-2010, Contest #1 Saratov, 2 August 2010