views:

269

answers:

2
A: 

I might do some BFI solution first, then perhaps look to generalize it or at least reduce it to a table-drive loop.

So, if it's exactly these shapes, and not a general solution, I think you should proceed sort of like this:

  1. Derive the coordinates of the blue rectangle. I suspect one thing that's confusing you is that you have each individual x and y for the blue rect but you can't easily loop through them.

  2. Derive the coordinates of the midpoint of each rectangle edge. You are going to need this because you care about quadrants. It will be trivial to do this once you have done 1.

  3. Write different code for each 1/2 rectangle edge. There is no doubt a more clever way but this will get working code.

  4. Make it more elegant now if you care. I betg you can reduce the rules to an 8-row table full of things like 1, -1, or something like that.

DigitalRoss
A: 

First, you can't define red area by a single vector, since it's disjoint. You need the same number of vectors as the number of distant red regions.

Second, do we assume that different red figures neither intersect nor share a border? In the next clause I do.

Third, under assumption in point 2, the quadrant will have all red outer side iff there exists a contiguous red figure that intersects both its axes (i.e. rays). To determine this for all quadrants, you should only traverse all (P) points in the order they're given. This takes linear time and solves the problem.

Pavel Shved