Falcon Dive
Time limit1sMemory limit256 MB
Shift the falcon silhouette by its frame-to-frame displacement and draw it over the shared background as a third frame.
- Level
Medium5 of 10
- Topics
- Matrix, Implementation
- Solved
- No attempts yet
Problem
"Our high speed camera failed at the worst possible moment," said the director of the zoo. "This sequence has the falcon hurtling towards the ground at 250 km/h, and I wanted it as a promotion picture. It would look good with the autumn trees in the background. But the falcon is too high even in the very last frame the camera caught before it broke."
"Cut the falcon out of the picture in Photoshop and move it downwards," said the falconer. "It is routine photo manipulation."
"That would be unnatural," objected the director. "We cannot show the public such obviously doctored pictures."
"On the contrary, that would be quite natural," replied the falconer. "At that speed the falcon barely changes its orientation, and its shape in the picture stays virtually the same over a few consecutive frames. So moving it down artificially still gives a very good approximation of what really happened during the filming."
After some hesitation the director agreed.
You are given the last two frames of the camera, each holding the silhouette of the falcon. The background is identical in both frames and only the position of the silhouette differs. The falcon moves at a constant speed and the time between consecutive frames is also constant. Reconstruct the missing next frame, in which the silhouette sits where the falcon's speed and the camera's speed put it. The background of the new frame is the same as the background of the previous two frames.
Input
The input holds several test cases. Each test case starts with a line holding two integers , () and a printable ASCII character enclosed in single quotes, separated by spaces. Next come lines, one empty line, and another lines. The first lines are the first frame and the last lines are the second frame. Each nonempty line is a string of exactly printable ASCII characters, and each character is one pixel of the original frame.
Both frames hold a complete silhouette of the falcon. In both frames every silhouette pixel is the character and every pixel outside the silhouette is a character other than . The silhouette pixels of the two frames do not overlap even partially: no coordinates of a silhouette pixel in the first frame match the coordinates of any silhouette pixel in the second frame. The two silhouettes have the same shape. Shifting the silhouette of one frame by some number of pixels horizontally and vertically makes it match the position of the silhouette in the other frame exactly. The silhouettes do not rotate. For technical reasons the silhouette image may be disconnected, so within one frame it can consist of several separate regions.
A printable ASCII character is one of the characters from the exclamation mark (!, ASCII code 33 in decimal) to the tilde (~, ASCII code 126 in decimal).
Successive test cases are separated by a blank line. The input ends with a line holding 0 0 ' '.
Output
For each test case, print one frame of lines with characters each. The frame is the exact extrapolation of the falcon's movement from the two input frames. If the silhouette in the second input frame is shifted horizontally and vertically by some number of pixels relative to the first input frame, then the silhouette in the result frame is shifted horizontally and vertically by the same number of pixels relative to the second frame. The silhouette may appear only partially in the frame, or it may not appear at all. Print one empty line after each test case.