Found your problem interesting. I'm not a mathematician or some kind of expert physicist, so I just think.
Is it possible to say that the overlap of two divs will lead to an overlap area, the opacity of which is to add two opacity divs. Therefore, if
D1 opacity = 0.1 and D2 opacity = 0.2 their overlap opacity = 0.3. (can it be?)
So, if 4 more divs are superimposed on them, if the addition reaches more than 1, this will mean that the combined overlap area will be completely black.
Alternatively, I can suggest you put your problem on programer.stackexchage.com too, people there just love algorithms :)
Well, maybe that doesn't work out that way. I created a simple jsFiddle. Someone here already has one way or another I will give you this link. http://jsfiddle.net/gHjrN/
Here I created four divs with different opacity. Their opacity has reached levels above 1.0, but still their collective overlap is not yet black. By the way, why are you looking for an algorithm, browsers seem to do it themselves: D
Well, I found a link that may prove useful opacity of overlapping partially transparent elements . The calculated opacity can be 1-(D1 opacity X D2 opacity)
source share