QOJ.ac

QOJ

시간 제한: 3 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓

#14253. 线球

통계

宝可梦中心刚刚推出了一种全新类型的精灵球。这种被称为 Line Ball 的精灵球比之前创造的任何其他精灵球都更加强大。投掷时,Line Ball 会沿着你所面对的方向呈直线向前飞行,并以 100% 的成功率捕捉它遇到的所有宝可梦!

宝可梦世界是一个巨大的 $m \times m$ 二维网格,其中网格的左下角方格坐标为 $(0, 0)$,右上角方格坐标为 $(m - 1, m - 1)$。在这个世界中,有 $n$ 只宝可梦,每只都位于网格的一个方格上。在投掷每颗 Line Ball 之前,你可以自由移动到宝可梦世界的任何方格(包括已经有宝可梦的方格),并面向四个基本方向之一。接着,你投掷的 Line Ball 将沿着你所面对的方向向前飞行,捕捉它经过的所有宝可梦(包括与你处于同一方格的任何宝可梦)。

图 1:投掷 Line Ball 并捕捉两只宝可梦的示例

给你一张描述每只宝可梦位置的地图,希望用 Line Ball 捕捉所有的宝可梦,且不花额外的钱。计算你必须投掷的 Line Ball 的最少数量,以便捕捉到每只宝可梦。

输入格式

第一行将包含两个由空格隔开的整数 $n$ 和 $m$ ($1 \le n, m \le 10\,000$),分别表示宝可梦的数量和宝可梦世界的大小。

接下来 $n$ 行,每行包含 2 个由空格隔开的整数 $x_i$ 和 $y_i$ ($0 \le x_i, y_i < m$),表示每只宝可梦的坐标。网格的同一个方格上可能会有多只宝可梦。

输出格式

输出一行,包含捕捉所有宝可梦所需购买的 Line Ball 的最少数量。

样例

输入样例 1

3 5
1 2
2 1
2 2

输出样例 1

2

输入样例 2

5 10
3 7
2 7
9 4
9 7
3 5

输出样例 2

3

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.