A8028 | Physical Education
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
输入格式
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}<=10^{9}$ ) 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}<=10^{9}$ ) 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.
输出格式
In the first line print an integer $k$ ( $0<=k<=10^{6}$ ) which is the number of moves. It is not required to minimize $k$ but it must not exceed $10^{6}$ . 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}$ .
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted