JOIN
Get Time
long_comps_topcoder  Problem Statement
Contest: Marathon Match 21
Problem: ShapePackaging

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)
    
width = 10
height = 10
1)
    
width = 20
height = 20
2)
    
width = 40
height = 40
3)
    
width = 70
height = 70
4)
    
width = 100
height = 100
5)
    
width = 14
height = 81
6)
    
width = 13
height = 22
7)
    
width = 11
height = 54
8)
    
width = 10
height = 49
9)
    
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)2010, TopCoder, Inc. All rights reserved.