wood burning stoves 2.0*
The moose likes Java in General and the fly likes assignment problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "assignment problem" Watch "assignment problem" New topic

assignment problem

Andrew Lit
Ranch Hand

Joined: Jul 01, 2002
Posts: 135
i've got a task, which i have no idea how to solve, this task sounds like this :
" you have N rectangles. and need to construct a rectangle of a maximum perimeter using given rectangles (only a part of given rectangles may be used) "
my problem is that i have no idea where to start from i tried to search the web, but i don't even know the name of the algorithm that must be used to solve the problem.
any help appreciated
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
Hi Andrew, these are just my ideas:
Given an atomic rectangle with sides b(height) and a(width):
| |
| |b
where a>b. The atomic perimeter P=2*(a+b). If you stack another rectangle side-by-side (which means their height to the right is common), the resulting rectangle perimeter is:
P1=2*(a+b)+2*a or 2*(a+b+a) or 2*(2a+b).
| | |
| | |b
If you stack a new rectangle on top of the existing one like this:
| |
| |
---------- 2b
| |
| |
The resulting perimeter is:
P2=2*(a+b)+2*b or 2*(2b+a).
Let's examine which structure is more beneficial in terms of getting the max perimeter. We will subtract the second case perimeter from the first case one:
Given a>b from the beginning, the result is positive and the first perimeter proved to be greater. Now, there are only two ways you can stack rectangles that we've examined above, so other combinations are impossible.
The rest is simple. You have N rectangles. You can use only part of them (I'd say, up to N-1 rectangles). We've seen that the max perimeter for 2 rectangles is P=2*(2a+b). For 3 rectangles the perimeter is 2(3a+b), and for N-1 rectangles the max perimeter is P=2*((N-1)*a+b)
I hope this helps ideas wise.
The output looks not what I drew, but I'm not in control.
[ November 16, 2003: Message edited by: Vad Fogel ]
I agree. Here's the link: http://aspose.com/file-tools
subject: assignment problem
Similar Threads
Tree and drawing within the same panel
exam question
object orientated applications in html/internet
web apps throw exception in jboss,run in tomcat
Design Pattern Extraction tool