Given X number of rectangular windows, what is the best packing on the screen to maximize window size and have no window totally obstructed by another?

First I start with a simple problem and then extrapolate to the general solution:

If we had four windows then the solution is:

Window A: 0, 0, W-1, H-1
Window B: 0, 1, W-1, H
Window C: 1, 0, W, H-1
Window D: 1, 1, W, H

W=Width of screen
H=Height of screen

Solution sets are composed of {X,Y,W,H}.

Seems simple enough. What about five windows?
Posted on 2003-08-25 10:40:05 by bitRAKE
I think that for five, we just add the window
;-- ---------------------\
a equ W-1
b equ H
.if W<H
a equ W
b equ H-1
.endif

{1,2,a,b} or {2,1,a,b}
;-----------------------/
Posted on 2003-08-25 15:50:31 by Ultrano
Ultrano, that is not correct because there are only four pixels not obstructed by more than one window (the corners). So, at least one other window needs to be moved -- just placing the new window is not sufficient.
Posted on 2003-08-25 15:53:23 by bitRAKE
Five Windows
Window A: 0, 0, W-1, H-2
Window B: 0, 1, W-1, H-1
Window C: 1, 0, W, H-2
Window D: 1, 1, W, H-1
Window E: 1, 1, W-1. H

Six Windows
Window A: 0, 1, W-1, H-2
Window B: 0, 2, W-1, H-1
Window C: 1, 1, W, H-2
Window D: 1, 2, W, H-1
Window E: 1, 1, W-1. H
Window F: 1, 0, W-1, H-1
Posted on 2003-08-27 21:57:24 by V Coder
Very good V Coder, so now we begin to see a pattern?
Posted on 2003-08-27 22:42:57 by bitRAKE
I don't :o think V Coder's correct. The answer should vary with (W-H).
Posted on 2003-08-28 01:09:01 by C.Z.
Assuming W>=H and N (number of windows) is even,

N<=2*(W+1)/(H+1): window extents = (W+1-N) by H
N>2*(W+1)/(H+1): window extents = (W+1-N/2) by (H-1)

Guess it should be so.
Posted on 2003-08-28 01:42:55 by C.Z.