Marathon Match 21 - Marathon Match 21

Register
Submit a solution
The challenge is finished.

Challenge Overview

Problem Statement

    

You are packing shapes into a box, and wish to pack as many as possible. Each shape must be packed one at a time, in the order they are received, and cannot be moved once packed. Shapes may not overlap, and may not extend beyond the bounds of the box.

Your goal is to pack the box as fully as possible, leaving as little empty space as possible. For each call of your placeTile method, return a int[] with three elements, x, y, and r, indicating the location and rotation of the shape to place. Placing a piece at (x,y) places the upper left corner of its bounding box at that location. Return an empty int[] when you are no longer able to pack an item into the box. Both the box and item parameters are such that the first character of the first string is the upper-left (0,0) of the box/piece and the last character of the last string is the bottom right. Each 'X' character indicates part of a piece, or a location in the box that is already filled, while each '.' character represents an empty location.

The width and height of the box are chosen between 10 and 100, uniformly at random. Each shape to place is a polyomino of size 4 or 5 that can be rotated in 90 degree increments, but not flipped over. There are 7 such pieces of size 4, and 18 of size 5. Each of the 25 total pieces is equally likely to be chosen next. An example of rotating a piece is shown below:

XXX     XX      X..     .X
..X     X.      XXX     .X
        X.              XX
r = 0   r = 1   r = 2   r = 3

Your raw score for each test case will be the amount of unused space in the box. (If your solution produces an error, makes an invalid move, etc, then all spaces are considered unused.) The total unused spaces over all cases will be summed for each submission. Your final score will be 1000 * best_sum / your_sum.

A visualization tool is available to aid you in development.
 

Definition

    
Class:ShapePackaging
Method:placeTile
Parameters:String[], String[]
Returns:int[]
Method signature:int[] placeTile(String[] box, String[] item)
(be sure your method is public)
    
 

Notes

-Runtime limit is 30 seconds per test case.
-Memory limit is 1024 MB.
 

Examples

0)
    
"1"
Returns: "width = 10
height = 10"
1)
    
"2"
Returns: "width = 20
height = 20"
2)
    
"3"
Returns: "width = 40
height = 40"
3)
    
"4"
Returns: "width = 70
height = 70"
4)
    
"5"
Returns: "width = 100
height = 100"
5)
    
"6"
Returns: "width = 14
height = 81"
6)
    
"7"
Returns: "width = 13
height = 22"
7)
    
"8"
Returns: "width = 11
height = 54"
8)
    
"9"
Returns: "width = 10
height = 49"
9)
    
"10"
Returns: "width = 12
height = 81"

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)2020, TopCoder, Inc. All rights reserved.