codeforces 686B

题意:给出一个序列,只允许进行相邻的两两交换,给出使序列变为非降序列的操作方案。

思路:关键点是操作次数不限,冒泡排序。

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll num[110];
int main() {
    int n;
    while(~scanf("%d",&n)) {
        for(int i=0;i<n;i++) {
            cin>>num[i];
        }
        int temp;
        for(int i=0;i<n;i++) {
            for(int j=0;j<n-1;j++) {
                if(num[j]>num[j+1]) {
                    temp=num[j+1];
                    num[j+1]=num[j];
                    num[j]=temp;
                    cout<<j+1<<" "<<j+2<<endl;
                }
            }
        }
    }
    
    return 0;
}
View Code

 

posted @ 2016-07-11 11:13  _LinesYao  阅读(148)  评论(0编辑  收藏  举报