Vision Program
문제
You are implementing a vision program for a robot. Each time the robot camera takes a picture, it is stored as a black and white image in the robot's memory. Each image is an grid of pixels, 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 consisting of simple instructions. You are given the values of , , and a positive integer . Your goal is to write a procedure to produce a program for the robot that, for any image, determines whether the distance between the two black pixels is exactly . Here, the distance between a pixel in row and column and a pixel in row and column is . In this formula denotes the absolute value of , which equals if and equals if .
We now describe how the robot works.
The robot's memory is a sufficiently large array of cells, indexed from . Each cell can store either or and its value, once set, will not be changed. The image is stored row by row in cells indexed through . The first row is stored in cells through , and the last row is stored in cells through . In particular, if the pixel in row and column is black, the value of cell is , otherwise it is .
A robot's program is a sequence of instructions, which are numbered with consecutive integers starting from . When the program is run, the instructions are executed one by one. Each instruction reads the values of one or more cells (we call these values the instruction's inputs) and produces a single value equal to or (we call this value the instruction's output). The output of instruction is stored in cell . The inputs of instruction can only be cells that store either pixels or outputs of previous instructions, i.e. cells to .
There are four types of instructions:
NOT: has exactly one input. Its output is if the input is , otherwise its output is .AND: has one or more inputs. Its output is if and only if all of the inputs are .OR: has one or more inputs. Its output is if and only if at least one of the inputs is .XOR: has one or more inputs. Its output is if and only if an odd number of the inputs are .
The output of the last instruction of the program should be if the distance between the two black pixels is exactly , and otherwise.