QOJ.ac

QOJ

実行時間制限: 7 s メモリ制限: 1024 MB 満点: 100

#5597. 孤单的骑士

統計

在国际象棋中,马的走法如下图所示;每次移动为水平一格垂直两格,或水平两格垂直一格。车可以水平或垂直移动任意格数,但不能在同一次移动中同时改变横纵坐标。如果一个格子可以通过车的一次移动到达,则称该格子受到车的攻击。

考虑一个无限大的棋盘,格子由整数坐标索引。棋盘上有一只白马,它想移动到另一个格子。然而,棋盘上还有若干黑车。马可以进行任意次数的移动以到达目标格子,但它不能停在受到车攻击或被车占据的格子上。车不会移动。

白马能到达它的目标格子吗?你需要多次回答这个问题!

输入格式

第一行包含两个整数 $n$ 和 $q$ ($1 \le n, q \le 1000$),其中 $n$ 是黑车的数量,$q$ 是询问的数量。

接下来的 $n$ 行,每行包含两个整数 $x$ 和 $y$。这表示在 $(x, y)$ 处有一只黑车。没有两只车占据同一个格子。

接下来的 $q$ 行,每行包含四个整数 $x_s, y_s, x_t$ 和 $y_t$。这是一个询问,表示白马从格子 $(x_s, y_s)$ 出发,想要移动到格子 $(x_t, y_t)$。

输入中所有格子的坐标绝对值均不超过 $10^9$。保证在每个询问中,马的起始格子和目标格子都没有受到任何车的攻击,也没有被任何车占据,且目标格子与起始格子不同。

输出格式

对于每个询问,如果马能到达目标格子,则输出 $1$,否则输出 $0$。

样例

样例输入 1

6 6
10 14
1 0
0 1
4 9
9 13
5 9
2 2 3 4
2 2 2 4
2 2 6 4
2 2 2 10
7 11 6 2
6 2 8 12

样例输出 1

1
0
0
1
0
1

样例输入 2

8 10
0 0
1 1
5 5
8 8
11 11
14 14
18 18
19 19
17 10 13 9
15 15 15 9
7 3 17 4
15 15 12 3
9 17 3 3
4 4 9 4
12 12 2 6
10 15 6 6
15 17 4 16
-1000000000 -999999999 15 7

样例输出 2

1
0
0
0
0
0
0
0
0
0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.