File size: 3,747 Bytes
e329daf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
<p>
The world's funniest schoolteacher has found himself in some trouble. Or, should we say, the world's funniest ex-schoolteacher.
On the basis of a false accusation regarding too many puns in his exam problems, Mr. X has not only been fired, but is now on the run from the Humane Association for Humour Administration (HAHA).
</p>
<p>
They've tracked Mr. X down to a yard in Scotland, which may be represented as a grid with <strong>N</strong> rows (numbered 1 to <strong>N</strong>)
and <strong>M</strong> columns (numbered 1 to <strong>M</strong>). Mr. X is initially in row <strong>A</strong> and column <strong>B</strong>.
There are also <strong>K</strong> (1 ≤ <strong>K</strong> ≤ 2) HAHA agents hot on his trail,
the <em>i</em>th of whom is initially in row <strong>R<sub>i</sub></strong> and column <strong>C<sub>i</sub></strong>. All <strong>K</strong>+1 individuals are in distinct cells.
</p>
<p>
The chase will then commence in an organized fashion as follows:
</p>
<ol>
<li>
Each of the <strong>K</strong> HAHA agents in turn will move up, down, left, or right to an adjacent unoccupied cell* (without leaving the yard).
The agents may choose to move in any order, but each of them must move exactly once, and multiple of them may not move simultaneously.
It's guaranteed that all of the agents will always be able to move in some order for any possible state of the yard.
</li>
<li>
Mr. X will then attempt to similarly move to an adjacent unoccupied cell. If he's unable to move due to there being no unoccupied cells adjacent to him, he'll surrender quietly instead.
Otherwise, the process will repeat from Step 1.
</li>
</ol>
<p>
* <em>An unoccupied cell is one which currently contains neither Mr. X nor an agent.</em>
</p>
<p>
Mr. X is hoping that, if he can avoid ever being forced to surrender, the HAHA agents may eventually leave him alone,
giving him the opportunity to slip away and work on regaining his teaching position.
However, the outcome of this chase seems difficult to call. Assuming that the agents work together optimally in an attempt to force Mr. X to surrender, while Mr. X optimally chooses moves to avoid surrendering indefinitely, determine whether or not he will eventually be forced to surrender.
</p>
<h3>Input</h3>
<p>
Input begins with an integer <strong>T</strong>, the number of times that Mr. X is chased by HAHA agents.
For each chase, there is first a line containing the space-separated integers <strong>N</strong>, <strong>M</strong>, and <strong>K</strong>.
Then there is a line containing the space-separated integers <strong>A</strong>, and <strong>B</strong>.
Then, <strong>K</strong> lines follow, the <em>i</em>th of which contains the space-separated integers
<strong>R<sub>i</sub></strong> and <strong>C<sub>i</sub></strong>.
</p>
<h3>Output</h3>
<p>
For the <em>i</em>th chase, print a line containing "Case #<em>i</em>: "
followed by one character, either "Y" if Mr. X will eventually be forced to surrender, or "N" otherwise.
</p>
<h3>Constraints</h3>
<p>
1 ≤ <strong>T</strong> ≤ 500 <br />
3 ≤ <strong>N</strong>, <strong>M</strong> ≤ 300 <br />
1 ≤ <strong>K</strong> ≤ 2 <br />
1 ≤ <strong>A</strong>, <strong>R<sub>i</sub></strong> ≤ <strong>N</strong> <br />
1 ≤ <strong>B</strong>, <strong>C<sub>i</sub></strong> ≤ <strong>M</strong> <br />
</p>
<h3>Explanation of Sample</h3>
<p>
In the first case, no matter how much time goes by and what moves the HAHA agent chooses to make, Mr. X can always avoid needing to surrender.
</p>
<p>
In the second case, if the first HAHA agent initially moves to cell (1, 2) and the second agent moves to cell (2, 1), then Mr. X will immediately be forced to surrender.
</p>
|