盖房子问题,请大家踊跃发表意见

arden1019 arden1019 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
这是google编程大赛入围赛题目之一,在http://www.blogjava.net/emu/articles/10191.html上作了一些讨论,可是我感觉都不全面。我总感觉可以提炼出一个比较好的数学模型,下面是题目:
请大家一起讨论啊。

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) A house side must contain no more than one door.
2) The house must have at least one door.
3) A door section may not be at the end of a wall.
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
0)


8
0
0
Returns: 0
No house can be built since you have no door sections.
1)


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-
2)


9
8
2
Returns: 144
One design is:
-D-
| |
D W
| |
-W-
3)


6
23
13
Returns: 48
We are very short of regular sections; one design is:
-
| |
D W
| |
-

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

...全文
评论 22
收藏 已收藏
分享
返回顶部
arden1019
C语言 70,039 成员 243,237 内容