QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 2048 MB Puntuación total: 100

#15629. 街机起重机

Estadísticas

当地的街机厅新安装了一款游戏,这是对经典抓娃娃机的一种全新诠释。

在机器内部,有 $n$ 个毛绒玩具排成一排。在这排玩具的上方,有一个由硬币驱动的机械爪。每投入一枚硬币,机械爪可以使用一次,从这一排中抓取恰好三个连续的毛绒玩具,然后将它们重新插入到这一排的某个位置。其余的毛绒玩具总是可以被推开(而不改变它们原本的相对顺序)以腾出空间进行重新插入。游戏的目标是将毛绒玩具按可爱度从小到大进行排序。一旦它们排好序,机器就会打开,完成这一目标的人将赢得所有的毛绒玩具。

图 A.1:样例输出 1 的图示。

Uli 非常想赢得这些毛绒玩具,因此他们做了一些研究,发现每个毛绒玩具都有一个介于 $1$ 到 $n$ 之间且互不相同的可爱度值。为了获胜,他们需要将毛绒玩具按照这些值的递增顺序进行排序。凭借对所有可爱度值的了解以及存有的 $5000$ 枚硬币,他们应该如何操作机器以确保赢得毛绒玩具?

输入格式

输入包含:

  • 第一行包含一个整数 $n$ ($5 \le n \le 1000$),表示毛绒玩具的数量。
  • 第二行包含 $n$ 个互不相同的整数 $a_1, \dots, a_n$ ($1 \le a_i \le n$ 对于每个 $i$),其中 $a_i$ 是第 $i$ 个毛绒玩具的可爱度值。

输出格式

首先,输出一个整数 $q$ ($0 \le q \le 5000$),表示操作的次数。

然后输出 $q$ 对整数 $i$ 和 $j$ ($1 \le i, j \le n - 2$),按顺序描述每次操作。机器中毛绒玩具的位置下标从 $1$ 到 $n$。在由 $i$ 和 $j$ 描述的操作中,位于位置 $i, i + 1$ 和 $i + 2$ 的毛绒玩具被抓取,然后重新插入到序列中,使得它们在操作后处于位置 $j, j + 1$ 和 $j + 2$。

可以证明,总是存在一个使用最多 $5000$ 次操作的解。

如果存在多个可行解,你可以输出其中任意一个。特别地,你不需要最小化操作次数。

样例

输入样例 1

5
3 5 2 1 4

输出样例 1

3
2 1
3 1
2 3

输入样例 2

6
6 5 4 3 2 1

输出样例 2

4
1 3
2 4
3 4
1 3

输入样例 3

9
9 2 8 5 4 6 7 3 1

输出样例 3

5
2 6
5 1
2 7
5 3
1 3

输入样例 4

5
1 2 3 4 5

输出样例 4

1
2 2

说明

注意,允许 $i = j$(这不会改变序列)。对于这个测试用例,也允许完全不使用任何操作,直接输出 “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.