1033A.md (3029B)
1 Source: https://codeforces.com/problemset/problem/1033/A 2 3 A. King Escape 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Alice and Bob are playing chess on a huge chessboard with dimensions $n \times n$. Alice has a single piece left — a queen, located at $(a_x, a_y)$, while Bob has only the king standing at $(b_x, b_y)$. Alice thinks that as her queen is dominating the chessboard, victory is hers. 22 23 But Bob has made a devious plan to seize the victory for himself — he needs to march his king to $(c_x, c_y)$ in order to claim the victory for himself. As Alice is distracted by her sense of superiority, she no longer moves any pieces around, and it is only Bob who makes any turns. 24 25 Bob will win if he can move his king from $(b_x, b_y)$ to $(c_x, c_y)$ without ever getting in check. Remember that a king can move to any of the $8$ adjacent squares. A king is in check if it is on the same rank (i.e. row), file (i.e. column), or diagonal as the enemy queen. 26 27 Find whether Bob can win or not. 28 29 Input 30 31 The first line contains a single integer $n$ ($3 \leq n \leq 1000$) — the dimensions of the chessboard. 32 33 The second line contains two integers $a_x$ and $a_y$ ($1 \leq a_x, a_y \leq n$) — the coordinates of Alice's queen. 34 35 The third line contains two integers $b_x$ and $b_y$ ($1 \leq b_x, b_y \leq n$) — the coordinates of Bob's king. 36 37 The fourth line contains two integers $c_x$ and $c_y$ ($1 \leq c_x, c_y \leq n$) — the coordinates of the location that Bob wants to get to. 38 39 It is guaranteed that Bob's king is currently not in check and the target location is not in check either. 40 41 Furthermore, the king is not located on the same square as the queen (i.e. $a_x \neq b_x$ or $a_y \neq b_y$), and the target does coincide neither with the queen's position (i.e. $c_x \neq a_x$ or $c_y \neq a_y$) nor with the king's position (i.e. $c_x \neq b_x$ or $c_y \neq b_y$). 42 43 Output 44 45 Print "YES" (without quotes) if Bob can get from $(b_x, b_y)$ to $(c_x, c_y)$ without ever getting in check, otherwise print "NO". 46 47 You can print each letter in any case (upper or lower). 48 49 Examples 50 51 Input 52 53 ``` 54 8 55 4 4 56 1 3 57 3 1 58 ``` 59 60 Output 61 62 ``` 63 YES 64 ``` 65 66 Input 67 68 ``` 69 8 70 4 4 71 2 3 72 1 6 73 ``` 74 75 Output 76 77 ``` 78 NO 79 ``` 80 81 Input 82 83 ``` 84 8 85 3 5 86 1 2 87 6 1 88 ``` 89 90 Output 91 92 ``` 93 NO 94 ``` 95 96 Note 97 98 In the diagrams below, the squares controlled by the black queen are marked red, and the target square is marked blue. 99 100 In the first case, the king can move, for instance, via the squares $(2, 3)$ and $(3, 2)$. Note that the direct route through $(2, 2)$ goes through check. 101 102  103 104 In the second case, the queen watches the fourth rank, and the king has no means of crossing it. 105 106  107 108 In the third case, the queen watches the third file. 109 110 