Vision Program
Time limit1sMemory limit1024 MB
Build a Boolean circuit of NOT, AND, OR, and XOR gates that outputs 1 when the two black pixels in an H by W image are exactly K apart.
- Level
Medium7 of 10
- Topics
- Implementation, Brute force, Math
- Solved
- No attempts yet
Problem
Each time the robot camera takes a picture, the image is stored as a black and white image in the robot's memory. Each image is an grid, with rows numbered through and columns numbered through . There are exactly two black pixels in each image, and all other pixels are white.
The robot can process each image with a program made of simple instructions. You are given , , and a positive integer . Write a procedure that produces a program which, for any image, determines whether the distance between the two black pixels is exactly . The distance between the pixel in row , column and the pixel in row , column is , where equals if and if .
The robot's memory is a sufficiently large array of cells indexed from . Each cell stores either or , and once set, its value does not change. The image is stored row by row in cells through . The first row is stored in cells through , and the last row is stored in cells through . If the pixel in row and column is black, cell holds ; otherwise it holds .
A robot program is a sequence of instructions numbered consecutively from . The instructions run one by one. Each instruction reads one or more cells (its inputs) and produces a single output, or . The output of instruction is stored in cell . The inputs of instruction can only be cells through , which hold pixels or outputs of earlier instructions.
There are four instruction types:
NOT: exactly one input. The output is if the input is , otherwise .AND: one or more inputs. The output is if and only if all inputs are .OR: one or more inputs. The output is if and only if at least one input is .XOR: one or more inputs. The output is if and only if an odd number of inputs are .
The output of the last instruction must be if the distance between the two black pixels is exactly , and otherwise.