| <p> | |
| Today you've found yourself standing on an infinite 2D plane at coordinates | |
| (<strong>X<sub>0</sub></strong>, <strong>Y<sub>0</sub></strong>). | |
| There are also <strong>N</strong> targets on this plane, with the <strong>i</strong>th one at coordinates | |
| (<strong>X<sub>i</sub></strong>, <strong>Y<sub>i</sub></strong>). | |
| </p> | |
| <p> | |
| You have a boomerang which you can throw in a straight line in any direction from your initial location. | |
| After you throw it, you may instantaneously run to any location on the plane. | |
| After the boomerang has travelled a | |
| distance of exactly <strong>D</strong> along its initial trajectory, it will return directly to you — | |
| that is, to your chosen final location. | |
| Note that you cannot move around once the boomerang has started its return trip — | |
| its path will always consist of 2 line segments (the first of which has a length of exactly <strong>D</strong>). The boomerang and the targets have infinitesimal size. | |
| </p> | |
| <p> | |
| Let <strong>A</strong> be the number of targets which your boomerang hits (directly passes through) | |
| during the first segment of its flight, and <strong>B</strong> be the number of targets which it hits | |
| during the second segment. Your throw is then awarded a score of <strong>A</strong> * <strong>B</strong>. | |
| What's the maximum score you can achieve? Note that, if there is a target at the exact location | |
| at which the two segments meet (at a distance of <strong>D</strong> from your initial location), | |
| then it counts towards both <strong>A</strong> and <strong>B</strong>! | |
| </p> | |
| <h3>Input</h3> | |
| <p> | |
| Input begins with an integer <strong>T</strong>, the number of planes. | |
| For each plane, there is first a line containing the space-separated integers | |
| <strong>X<sub>0</sub></strong> and <strong>Y<sub>0</sub></strong>. | |
| The next line contains the integer <strong>D</strong>, and the one after contains the integer <strong>N</strong>. | |
| Then, <strong>N</strong> lines follow, the <strong>i</strong>th of which contains | |
| the space-separated integers <strong>X<sub>i</sub></strong> and <strong>Y<sub>i</sub></strong>. | |
| </p> | |
| <h3>Output</h3> | |
| <p> | |
| For the <strong>i</strong>th plane, print a line containing "Case #<strong>i</strong>: " followed by | |
| the maximum score you can achieve. | |
| </p> | |
| <h3>Constraints</h3> | |
| <p> | |
| 1 ≤ <strong>T</strong> ≤ 20 <br /> | |
| 1 ≤ <strong>N</strong> ≤ 3,000 <br /> | |
| 1 ≤ <strong>D</strong> ≤ 100 <br /> | |
| -100 ≤ <strong>X<sub>i</sub></strong>, <strong>Y<sub>i</sub></strong> | |
| ≤ 100, for 0 ≤ <strong>i</strong> ≤ <strong>N</strong> <br /> | |
| </p> | |
| <p> | |
| All coordinates are pairwise distinct. The following restrictions are also guaranteed to hold for | |
| the input given: | |
| </p> | |
| <p> | |
| For any three targets at distinct points <strong>a</strong>, <strong>b</strong>, and <strong>c</strong>, | |
| it is guaranteed that <strong>c</strong> is either closer than 10<sup>-13</sup> away from the infinite line | |
| between <strong>a</strong> and <strong>b</strong> (and is considered to be on the line), or is further | |
| than 10<sup>-6</sup> away (and is considered to not be on the line). | |
| </p> | |
| <p> | |
| Let <strong>p</strong> be any point at which the boomerang may change direction after hitting a target. | |
| For any two targets at distinct points <strong>a</strong> and <strong>b</strong>, | |
| it is guaranteed that <strong>p</strong> is either closer than 10<sup>-13</sup> away from the infinite line | |
| between <strong>a</strong> and <strong>b</strong> (and is considered to be on the line), or is further | |
| than 10<sup>-6</sup> away (and is considered to not be on the line). | |
| </p> | |
| <h3>Explanation of Sample</h3> | |
| <p> | |
| On the first plane, one optimal strategy is to throw the boomerang in the direction of the positive x-axis | |
| (that is, to (6, 0)), and then run to (0, 0). It will hit targets 2 and 3 on the first segment of its flight, | |
| and all 3 targets on the second segment, for a score of 2*3=6. | |
| </p> | |