forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatrolRoute.html
More file actions
11 lines (11 loc) · 4.79 KB
/
Copy pathPatrolRoute.html
File metadata and controls
11 lines (11 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
<html><body bgcolor="#cccccc" text="#000000"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td><p>There are exactly <b>X</b>*<b>Y</b> places in the Planar Kingdom: For each pair of integers (x, y) such that 0 <= x < <b>X</b> and 0 <= y < <b>Y</b> there is a place with coordinates (x, y). When a citizen of the kingdom wants to move from (x1, y1) to (x2, y2), the required time is |x1 - x2| + |y1 - y2| (where |t| denotes the absolute value of t).</p>
<p></p>
<p>In order to improve stability in the kingdom, the police wants to introduce a specific <i>patrol route</i>. The route will contain exactly three places A, B, and C.
A policeman will visit these three places and verify that everything is as it should be. The three places that determine a valid route must satisfy the following criteria::
<ul>
<li>x-coordinates of A, B and C are pairwise distinct.</li>
<li>y-coordinates of A, B and C are pairwise distinct.</li>
<li>Let T be the total time required to follow along the route: first from A to B, then from B to C and finally from C back to A. T must be between <b>minT</b> and <b>maxT</b>, inclusive.</li>
</ul></p>
<p></p>
You are given the ints <b>X</b>, <b>Y</b>, <b>minT</b>, and <b>maxT</b>. Return the number of different patrol routes that satisfy these criteria, modulo 1,000,000,007. Two routes are considered to be different if there is a place that belongs to one of them, but does not belong to the other one.</td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>PatrolRoute</td></tr><tr><td>Method:</td><td>countRoutes</td></tr><tr><td>Parameters:</td><td>int, int, int, int</td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int countRoutes(int X, int Y, int minT, int maxT)</td></tr><tr><td colspan="2">(be sure your method is public)</td></tr></table></td></tr><tr><td>    </td></tr><tr><td></td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>X</b> and <b>Y</b> will each be between 3 and 4,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>minT</b> will be between 1 and 20,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>maxT</b> will be between <b>minT</b> and 20,000, inclusive.</td></tr><tr><td colspan="2"><h3>Examples</h3></td></tr><tr><td align="center" nowrap="true">0)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>3</pre></td></tr><tr><td><pre>3</pre></td></tr><tr><td><pre>1</pre></td></tr><tr><td><pre>20000</pre></td></tr></table></td></tr><tr><td><pre>Returns: 6</pre></td></tr><tr><td><table><tr><td colspan="2">The time requirement is very flexible in this case. There are 6 patrol routes where both x and y coordinates of places are pairwise distinct.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">1)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>3</pre></td></tr><tr><td><pre>3</pre></td></tr><tr><td><pre>4</pre></td></tr><tr><td><pre>7</pre></td></tr></table></td></tr><tr><td><pre>Returns: 0</pre></td></tr><tr><td><table><tr><td colspan="2">The time of 7 is too small for any patrol route.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">2)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>4</pre></td></tr><tr><td><pre>6</pre></td></tr><tr><td><pre>9</pre></td></tr><tr><td><pre>12</pre></td></tr></table></td></tr><tr><td><pre>Returns: 264</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">3)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>7</pre></td></tr><tr><td><pre>5</pre></td></tr><tr><td><pre>13</pre></td></tr><tr><td><pre>18</pre></td></tr></table></td></tr><tr><td><pre>Returns: 1212</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">4)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>4000</pre></td></tr><tr><td><pre>4000</pre></td></tr><tr><td><pre>4000</pre></td></tr><tr><td><pre>14000</pre></td></tr></table></td></tr><tr><td><pre>Returns: 859690013</pre></td></tr><tr><td><table><tr><td colspan="2">Don't forget about the modulo!</td></tr></table></td></tr></table></td></tr></table><p>This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved. </p></body></html>