Physical Education
来源:互联网 发布:数学编程 编辑:程序博客网 时间:2024/05/22 04:57
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: a1, a2, ..., an, where ai 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: b1, b2, ..., bn, which upset Vasya immensely. Now Vasya wants to rearrange the children so that the resulting order is like this: a1, a2, ..., an. 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 ai (1 ≤ ai ≤ 109) which represent the height of the student occupying the i-th place must possess. The third line contains n space-separated integers bi (1 ≤ bi ≤ 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.
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 pi, pi + 1 (1 ≤ pi ≤ n - 1) means that Vasya should swap students occupying places pi and pi + 1.
41 2 3 23 2 1 2
42 31 23 42 3
21 1005001 100500
0
其实是挺简单的一道构造题。。但是开始没做对。
下面是AC代码:
#include<iostream>#include<algorithm>#include<vector>#include<windows.h>using namespace std;int main(){int a[303],b[303],i,j,n;vector<int >x,y;cin>>n;for(i=1;i<=n;i++) cin>>a[i];for(i=1;i<=n;i++) cin>>b[i];for(i=1;i<=n;i++){for(j=i;j<=n;j++){if(a[i]==b[j])break;}while(j>i){swap(b[j-1],b[j]);x.push_back(j-1);y.push_back(j);j--;}}cout<<x.size()<<endl;for(i=0;i<x.size();i++)cout<<x[i]<<" "<<y[i]<<endl;return 0;}
- Physical Education
- Physical Education CodeForces
- Codeforces 394D Physical Education and Buns
- CF-394D Physical Education and Buns
- URAL 2052 Physical Education(数位dp+二分)
- URAL 2052 . Physical Education (数位DP + 二分)
- URAL 2052 Physical Education(数位dp)
- Codeforces 394D Physical Education and Buns(暴力)
- Codeforces 394D Physical Education and Buns 胡搞
- Education Background
- American Education
- Ideal education
- Education Pays
- online-education
- schools and education (transfer)
- HP Openvms education training
- Education教育
- thinking in education
- linux磁碟分区档的命名
- xshell连接centos乱码
- VC++中窗口创建的流程
- 多线程基础(单读、单写、循环队列、无锁、lockfree)
- eclipse 错误信息 "File Search" has encounter a problem 解决
- Physical Education
- Light OJ 1008
- 专访:八年JAVA开发项目经理技术路
- 垂直搜索
- vb工程21--百例41--五彩碎纸
- MyBatis 点点滴滴
- 如何测试apk文件?
- form的onsubmit验证
- linux 进程控制入门