That's a good catch, Richard! (even easier proof: Consider a square where the area lies entirely inside of it. QED).
Perhaps solvable by gridding with the finest detail we'll ever need, and to grid around the bucket as origin instead of the top-left of the field. (because the bucket is guaranteed to be an "in" point); at the finest detail level, if all points are indeed 0, even if a tiny part is intruding into our square, at least the error is managable then. For any square whose side facing away from the bucket is all clear, given that A is convex, we can basically color the rest of the field in that direction as 'all clear' too which may offer a different way to somewhat quickly establish large parts of the field as "not in A". Something I'll need to think more about, and a real problem for the "easy to write" part of this algorithm :( About the intersection of two circles: First establish the two points where the circles overlap each other. This doesn't have to happen of course (they may only touch on one point or be entirely separate, or one circle may lie entirely in another), though I believe this will always be true because no two goats are co-linear with the bucket and the bucket is on the circumference of all circles). At any rate, if there are less than 2 intersect points the answer is trivial (either the area of the smaller circle or 0). Then, draw a line between these two points. Now consider that the area consists of two 'wedges', one to the left of this line and on to the right of it. Each wedge corresponds to the area of the arc of one of the two circles (from one intersect point to the other), minus the area of the triangle formed by the line we drew + the radius lines of that arc. Add up the area of these two wedges and you have an answer. Whether the intersection is tiny or gigantic, this algorithm will do the trick. All you need to do then is figure out the "length" of the arc bounded by these two intersect points for both of the circles and you have all you need; the area of the triangle can be stated using that arc length, the area of the arc itself can be derived easily with it as well. On Jun 6, 12:29 pm, Amtep <[email protected]> wrote: > On Sat, Jun 05, 2010 at 02:05:25PM -0700, Reinier Zwitserloot wrote: > > I'm really kicking myself for deciding to try and finish C-large which > > failed, I should have spent the time to read D fully, realize the D- > > small is just asking to calculate the intersection of 2 circles 10,000 > > times, which is completely trivial - just google around for the > > formula if you can't derive it yourself. > > I considered this, but I didn't attempt it because I was feeling too > much time pressure. The derivations I found online seemed to consider only > small intersections, not one where most of one circle lies inside the other. > Like this derivation: > http://mathforum.org/library/drmath/view/54785.html > Can someone tell me if it would have worked, so I can kick myself too? :) > > > There's one big intuitive leap you'd have to make which I'm not 100% > > sure about, and it is this: > > > Given the square box drawn by [x1,y1] to [x2,y2], then this entire box > > lies inside of A if points [x1,y1], [x1,y2], [x2,y1] and [x2,y2] are > > ALL inside A. Similarly, the entire box lies outside of A if all those > > points lie outside of A. > > I think the first assumption holds but not the second. For a simple > counterexample, consider a rectangle that contains all of A. > Also look at the left-side pictures in the problem description, where > A is an elongated shape. One point of that shape could intrude in > the side of a rectangle without touching any of the corners. > > So, I don't think this works unless you have some other way of ruling > out the rectangles that lie outside of A. > > -- > Richard Braakman > > We can achieve more by promoting generosity, awareness, and freedom > than we can by vainly kicking at a buttless foe. -- VHEMT -- You received this message because you are subscribed to the Google Groups "google-codejam" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-code?hl=en.
