TopCoder problem "FloorTiling" used in TCO05 Round 2 (Division I Level One)



Problem Statement

    You are tiling a floor that is width by height units. You are using strips of tile that are size by 1 units. The long side of the tiles should run along the side of the floor that is width units long. See the diagram for more details on exactly how the tiles should be placed.



Note how each row is offset by offset units from the one below it. (When thinking of how to offset the rows, imagine infinite horizontal strips of tiles.) Also, notice that the bottom row is touching the side. As the diagram illustrates, you will not be able to tile the whole floor with pieces that are size by 1. You should return the area of the region that will not be covered when tiling according to the strategy shown in the image.
 

Definition

    
Class:FloorTiling
Method:tile
Parameters:int, int, int, int
Returns:int
Method signature:int tile(int size, int offset, int width, int height)
(be sure your method is public)
    
 

Constraints

-offset will be between 0 and size-1, inclusive.
-size will be between 2 and floor(width/2), inclusive.
-width and height will each be between 4 and 50, inclusive.
 

Examples

0)
    
3
2
7
8
Returns: 17
The example in the diagram above.
1)
    
5
1
10
8
Returns: 30
2)
    
2
1
50
50
Returns: 50

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=4709

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=8017&pm=4709

Writer:

lars2520

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Math