10790 - How Many Points of Intersection

download 10790 - How Many Points of Intersection

If you can't read please download the document

description

probleme de programare

Transcript of 10790 - How Many Points of Intersection

10790 - How Many Points Of Intersection?http://www.questtosolve.com/browse.php?pid=10790Solved By:wesleyTheory Difficulty:easyCoding Difficulty:trivialAlgorithms Used:mathSolution Description: To get a feel for how the pattern in this problem works, take the example of four dots in the bottom row, and one dot on top. Let the dots in the bottom be B1...B4, and the dot on top be A1. There are no points of intersection.

If we add another dot on top (A2), then the line A2-B1 crosses 3 lines, A2-B2 crosses 2 lines, A2-B3 crosses 1 line, and A2-B4 crosses 0.

If we add A3, then we get 6 intersections, then 4, then 2. Adding A4 gives us 9, then 6, then 3. Look at this pattern:

03 + 2 + 16 + 4 + 29 + 6 + 3...

Or more explicitly:01 * (3 + 2 + 1)2 * (3 + 2 + 1)3 * (3 + 2 + 1)

Note that there is a triangular number sequence going horizontally, and a triangular number sequence going vertically. This gives us the final result of:

tri(A) * tri(B)= A(A-1)/2 * B(B-1)/2