TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

HouseParty

Problem statement, definition, constraints, and public examples.

Problem Statement

We are building a rectangular house using manufactured sections for the walls. Each section is 4 feet long. There are three types of sections: window sections, door sections, and regular sections. We have a fixed assortment of these sections, and want to design the house to have a maximum area, subject to the following rules:
  1. 1) A house side must contain no more than one door.
  2. 2) The house must have at least one door.
  3. 3) A door section may not be at the end of a wall.
  4. 4) Each window section must be adjacent to two regular sections, one on each side of it in its wall.
Create a class HouseParty that contains a method maxArea that is given numReg, numWin, and numDoor (the available quantity of each type of section) and that returns the maximum area of a house built from those sections. You are not required to use all the sections. If no house can be built your method should return 0.

Definition

Class:
HouseParty
Method:
maxArea
Parameters:
int, int, int
Returns:
int
Method signature:
int maxArea(int numReg, int numWin, int numDoor)
(be sure your method is public)

Constraints

  • numReg, numWin, and numDoor will each be between 0 and 50 inclusive.

Examples

  1. 8
    0
    0
    Returns: 0
    No house can be built since you have no door sections.
  2. 8
    0
    1
    Returns: 48
    One way is to use 3 regular sections for the north wall, one regular section for the east wall and one for the west wall, and to use a door section between 2 regular sections for the south wall. This gives a house that is 12' x 4'. Below is a picture (with door and window sections shown as D and W, and regular sections shown as - or | ) --- | | -D-
  3. 9
    8
    2
    Returns: 144
    One design is: -D- | | D W | | -W-
  4. 6
    23
    13
    Returns: 48
    We are very short of regular sections; one design is: - | | D W | | -
Back to all problems