Coin Puzzle
InterviewTime limit1sMemory limit1024 MB
Given two coin grids of up to 10 by 10, find the fewest coins to move so the first arrangement becomes the second by translation only.
- Level
Easy3 of 10
- Topics
- Brute force, Implementation
- Solved
- No attempts yet
Problem
Solve a coin puzzle! At the start, some coins are placed on an infinite grid plane. Every coin sits on a lattice point.
The goal of the puzzle is to create a new shape by moving the fewest possible coins. Each move picks up one coin and places it on an empty lattice point. The new shape may appear at any position, but making a rotated or reflected shape is not allowed.
For example, consider the following two coin arrangements.

To turn the first arrangement into the second, at least four coins must be moved, as shown below.

Given the current coin arrangement and the arrangement to be made, find the minimum number of coins that must be moved.
Input
The first line contains integers and (). The next lines each contain a string of length . '.' is an empty cell and 'O' is a cell with a coin. This describes the current arrangement of coins.
The next line contains integers and (). The next lines each contain a string of length , using the same notation. This describes the arrangement of coins to be made.
The two arrangements are guaranteed to have the same number of coins.
Output
Print the minimum number of coins that must be moved.