Member Search

Problem Statement

Your job is to unscramble a photograph in the fewest number of iterations possible.

The image is divided up into uniformly-sized square pieces and the pieces are shuffled. Your method will be provided with the size of each piece in pixels (the width and height are the same), the number of columns and rows of pieces in the image, and an array of pixel values. Each pixel value is encoded as an integer with eight bits per color component in RGB order, from most significant to least significant. You can decode each pixel with int red = (pixel >> 16), green = (pixel >> 8) & 0xff, blue = pixel & 0xff;.

Pieces are numbered from zero to rows*columns-1. Given a piece n, the image data for that piece can be found in row-major order in the pixels array starting at n*pieceSize*pieceSize. You can extract the pixel value at line y and column x of piece n with the expression pixels[n*pieceSize*pieceSize+y*pieceSize+x].

You are provided with a verify method which tells you which pieces are in the correct places in a guess. You pass it an array containing rows*columns integers, each of which represents a slot in the image in row major order so that the guess for the slot at row r and column c is at r*columns+c. Each slot should contain a piece number as described above. The method returns a corresponding array of integers. If the guess for a particular slot is correct, the corresponding return slot will be 1; otherwise, it will be 0. This means that it is possible to create the correct image without looking at the pixel data.

Your solution must return a guess in the same format as would be passed to the verify method. Your raw score for each case will be 1 plus the number of calls made to verify, or zero if your solution does not return the pieces in the correct order. Your aggregated score will be the sum of the lowest raw score received by any competitor on a case divided by your score on the case, excluding any cases in which you received a raw zero.

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.