CF1033A.King Escape

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alice and Bob are playing chess on a huge chessboard with dimensions n×nn \times n. Alice has a single piece left — a queen, located at (ax,ay)(a_x, a_y), while Bob has only the king standing at (bx,by)(b_x, b_y). Alice thinks that as her queen is dominating the chessboard, victory is hers.

But Bob has made a devious plan to seize the victory for himself — he needs to march his king to (cx,cy)(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.

Bob will win if he can move his king from (bx,by)(b_x, b_y) to (cx,cy)(c_x, c_y) without ever getting in check. Remember that a king can move to any of the 88 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.

Find whether Bob can win or not.

爱丽丝和鲍勃正在一个 n×nn \times n 的巨型棋盘上对弈国际象棋。爱丽丝只剩一枚棋子——位于 (ax,ay)(a_x, a_y) 的皇后;而鲍勃仅剩一枚国王,位于 (bx,by)(b_x, b_y)。爱丽丝认为,由于她的皇后统治着整个棋盘,胜利已稳操胜券。

但鲍勃制定了一个阴险的计划,意图为自己夺取胜利——他需要将自己的国王行进至 (cx,cy)(c_x, c_y) 才能宣告自己获胜。由于爱丽丝正沉醉于自己的优越感之中,她不再移动任何棋子,整盘棋仅由鲍勃走子。

若鲍勃能将其国王从 (bx,by)(b_x, b_y) 移动到 (cx,cy)(c_x, c_y),且全程不被将军,则鲍勃获胜。注意:国王可移向其周围 88 个相邻格子中的任意一个。当国王与敌方皇后处于同一横线(即同一行)、同一竖线(即同一列)或同一斜线上时,即为被将军。

请判断鲍勃能否获胜。

输入格式

The first line contains a single integer nn (3≤n≤10003 \leq n \leq 1000) — the dimensions of the chessboard.

The second line contains two integers axa_x and aya_y (1≤ax,ay≤n1 \leq a_x, a_y \leq n) — the coordinates of Alice's queen.

The third line contains two integers bxb_x and byb_y (1≤bx,by≤n1 \leq b_x, b_y \leq n) — the coordinates of Bob's king.

The fourth line contains two integers cxc_x and cyc_y (1≤cx,cy≤n1 \leq c_x, c_y \leq n) — the coordinates of the location that Bob wants to get to.

It is guaranteed that Bob's king is currently not in check and the target location is not in check either.

Furthermore, the king is not located on the same square as the queen (i.e. ax≠bxa_x \neq b_x or ay≠bya_y \neq b_y), and the target does coincide neither with the queen's position (i.e. cx≠axc_x \neq a_x or cy≠ayc_y \neq a_y) nor with the king's position (i.e. cx≠bxc_x \neq b_x or cy≠byc_y \neq b_y).

第一行包含一个整数 nn(3≤n≤10003 \leq n \leq 1000)——棋盘的边长。

第二行包含两个整数 axa_x 和 aya_y(1≤ax,ay≤n1 \leq a_x, a_y \leq n)——爱丽丝的皇后所在位置的坐标。

第三行包含两个整数 bxb_x 和 byb_y(1≤bx,by≤n1 \leq b_x, b_y \leq n)——鲍勃的国王所在位置的坐标。

第四行包含两个整数 cxc_x 和 cyc_y(1≤cx,cy≤n1 \leq c_x, c_y \leq n)——鲍勃希望国王到达的目标位置的坐标。

保证鲍勃的国王当前未处于被将军状态,且目标位置也未处于被将军状态。

此外,国王不与皇后位于同一格子上(即 ax≠bxa_x \neq b_x 或 ay≠bya_y \neq b_y),且目标位置既不与皇后位置重合(即 cx≠axc_x \neq a_x 或 cy≠ayc_y \neq a_y),也不与国王当前位置重合(即 cx≠bxc_x \neq b_x 或 cy≠byc_y \neq b_y)。

输出格式

Print "YES" (without quotes) if Bob can get from (bx,by)(b_x, b_y) to (cx,cy)(c_x, c_y) without ever getting in check, otherwise print "NO".

You can print each letter in any case (upper or lower).

如果鲍勃能够从 (bx,by)(b_x, b_y) 移动到 (cx,cy)(c_x, c_y),且在此过程中从未处于被将杀(check)状态,则输出 "YES"(不带引号);否则输出 "NO"。

你可以以任意大小写形式输出每个字母(大写或小写)。

输入输出样例

  • 输入#1

    8
    4 4
    1 3
    3 1

    输出#1

    YES
  • 输入#2

    8
    4 4
    2 3
    1 6

    输出#2

    NO
  • 输入#3

    8
    3 5
    1 2
    6 1

    输出#3

    NO

说明/提示

In the diagrams below, the squares controlled by the black queen are marked red, and the target square is marked blue.

In the first case, the king can move, for instance, via the squares (2,3)(2, 3) and (3,2)(3, 2). Note that the direct route through (2,2)(2, 2) goes through check.

In the second case, the queen watches the fourth rank, and the king has no means of crossing it.

In the third case, the queen watches the third file.

在下面的图示中,黑后控制的格子标为红色,目标格子标为蓝色。

在第一种情况下,王可以移动,例如经过格子 (2,3)(2, 3) 和 (3,2)(3, 2)。注意:经由 (2,2)(2, 2) 的直接路径会进入被将军状态。

在第二种情况下,后控制着第四横线(即第 4 排),王无法越过该横线。

在第三种情况下,后控制着第三竖线(即第 3 列)。

输入解题思路,AI测评打分。不知道怎么写?

首页