CF53D.Physical Education

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: _a_1, _a_2, ..., a__n, where a__i is the height of the i-th student in the line and n is the number of students in the line. The children find it hard to keep in mind this strange arrangement, and today they formed the line in the following order: _b_1, _b_2, ..., b__n, which upset Vasya immensely. Now Vasya wants to rearrange the children so that the resulting order is like this: _a_1, _a_2, ..., a__n. During each move Vasya can swap two people who stand next to each other in the line. Help Vasya, find the sequence of swaps leading to the arrangement Vasya needs. It is not required to minimize the number of moves.

瓦西娅是一名学校体育老师。与其他体育老师不同,瓦西娅不喜欢学生按身高排队。相反,他要求孩子们按如下顺序站成一排:a1, a2, …, ana_1,\ a_2,\ \dots,\ a_n,其中 aia_i 表示队列中第 ii 个学生的身高,nn 是队列中的学生总数。孩子们很难记住这种奇怪的排列方式,因此今天他们自行排成了如下顺序:b1, b2, …, bnb_1,\ b_2,\ \dots,\ b_n,这让瓦西娅极为不满。现在,瓦西娅希望重新安排孩子们,使最终队列变为他所要求的顺序:a1, a2, …, ana_1,\ a_2,\ \dots,\ a_n。在每次操作中,瓦西娅可以交换队列中相邻的两名学生。请帮助瓦西娅,找出一系列交换操作,使得队列最终变为他所要求的顺序。不要求最小化操作次数。

输入格式

The first line contains an integer n (1 ≤ n ≤ 300) which is the number of students. The second line contains n space-separated integers a__i (1 ≤ a__i ≤ 109) which represent the height of the student occupying the i-th place must possess. The third line contains n space-separated integers b__i (1 ≤ b__i ≤ 109) which represent the height of the student occupying the i-th place in the initial arrangement. It is possible that some students possess similar heights. It is guaranteed that it is possible to arrange the children in the required order, i.e. a and b coincide as multisets.

第一行包含一个整数 nn(1≤n≤3001 \leq n \leq 300),表示学生的数量。
第二行包含 nn 个以空格分隔的整数 aia_i(1≤ai≤1091 \leq a_i \leq 10^9),表示第 ii 个位置上学生所需具备的身高。
第三行包含 nn 个以空格分隔的整数 bib_i(1≤bi≤1091 \leq b_i \leq 10^9),表示初始排列中第 ii 个位置上学生的身高。
可能存在若干学生身高相同。
保证可以将学生重新排列成所要求的顺序,即 aa 和 bb 作为多重集是相同的。

输出格式

In the first line print an integer k (0 ≤ k ≤ 106) which is the number of moves. It is not required to minimize k but it must not exceed 106. Then print k lines each containing two space-separated integers. Line p__i, p__i + 1 (1 ≤ p__i ≤ n - 1) means that Vasya should swap students occupying places p__i and p__i + 1.

第一行输出一个整数 kk(0≤k≤1060 \leq k \leq 10^6),表示操作次数。无需最小化 kk,但必须满足 k≤106k \leq 10^6。随后输出 kk 行,每行包含两个以空格分隔的整数。第 ii 行的 pip_i, pi+1p_i+1(其中 1≤pi≤n−11 \leq p_i \leq n-1)表示瓦西亚应交换占据位置 pip_i 和 pi+1p_i+1 的两名学生。

输入输出样例

  • 输入#1

    4
    1 2 3 2
    3 2 1 2

    输出#1

    4
    2 3
    1 2
    3 4
    2 3
  • 输入#2

    2
    1 100500
    1 100500

    输出#2

    0

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

首页