QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 2048 MB Points totaux : 100

#14563. 骑行需求

Statistiques

在垂直骑行网格城(Grid City of Perpendicular Cycling,简称 GCPC)中,汽车从未流行过。相反,每个人都使用各种自行车在城市中穿行。这并非 GCPC 的唯一特色。遵循至少自公元前 2600 年起就在不同地方使用的古老城市设计,所有街道都沿着基本方向(即南北向或东西向)延伸,因此它们仅以直角相交。

城市委员会正计划新建一条环绕整个城市的自行车道,以满足对良好自行车基础设施的强烈需求。这条新的自行车道应当尊重历史悠久的网格系统,因此只能由平行于基本方向之一的线段组成。

为了最大限度地降低建设成本并减少骑行者的出行时间,委员会希望这条新的自行车道尽可能短。委员会已经准备好了城市的轮廓,但现在需要帮助来寻找这样一条最短的自行车道。为简单起见,你可以假设自行车道的宽度为零,并且到城市轮廓上任意点的距离可以为零。

图 D.1:第一个样例的示意图。灰色区域表示城市,黑色轮廓表示一条最优的自行车道。给定的自行车道长度为 20。可以证明,不存在更短的满足要求的自行车道。

输入格式

输入包含:

  • 一行,包含一个整数 $n$($4 \le n \le 10^5$),表示城市轮廓的点数。
  • $n$ 行,每行包含两个整数 $x$ 和 $y$($1 \le x, y \le 10^9$),表示这些点的坐标。

此外,保证满足以下条件:

  • 城市轮廓的点按逆时针顺序给出。
  • 任意两个相邻的点具有相同的 $x$ 坐标或相同的 $y$ 坐标。
  • 任意连续三个点不共线。
  • 城市轮廓不自交。

输出格式

输出一个整数 $m$($m \le n$),表示自行车道的点数,随后是 $m$ 行,按逆时针顺序包含自行车道的坐标。注意,任意两个相邻的点必须具有相同的 $x$ 坐标或相同的 $y$ 坐标,且任意连续三个点不能共线。

如果存在多个有效解,你可以输出其中任意一个。

样例

输入样例 1

8
1 2
3 2
3 4
5 4
5 1
7 1
7 5
1 5

输出样例 1

6
7 5
1 5
1 2
5 2
5 1
7 1

输入样例 2

8
1 1
4 1
4 3
3 3
3 4
2 4
2 2
1 2

输出样例 2

8
4 3
3 3
3 4
2 4
2 2
1 2
1 1
4 1

输入样例 3

12
1 3
1 2
2 2
2 1
3 1
3 2
4 2
4 3
3 3
3 4
2 4
2 3

输出样例 3

12
4 3
3 3
3 4
2 4
2 3
1 3
1 2
2 2
2 1
3 1
3 2
4 2

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.