hrbust 1739 Sort Problem 模拟

Sort Problem
Time Limit: 1000 MSMemory Limit: 65535 K
Total Submit: 343(88 users)Total Accepted: 182(86 users)Rating: Special Judge: Yes
Description

You have a sequence of N (1 <= N <= 10 000) numbers (none of the numbers is equal to others), can you let the sequence become ascending within N movements.

Input

There are multiple test cases. The first line is a positive integer T, indicating the number of test cases.

For each test case:

Line 1. A positive integer N.

Line 2. This line contains N integers: a1, a2, ..., ai, ...,an (0 < ai <= 2 000 000 000) separated by space.


Output

For each test case, output m at the first line. m is the times of operation.

Then m lines follows. Each line consists two integer x, y meaning that you will change the number on position x and the number on position y.


Sample Input
3
3
2 3 1
5
1 2 5 3 4
10
11 3 17 19 7 2 20 15 10 13
Sample Output
2
1 3
2 3
2
3 4
4 5
7
1 6
3 5
4 9
5 6
6 10
7 8
8 10
Source
哈理工2013春季校赛 - 现场赛
#include<stdio.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int a[100003],b[100003];
int vis[100003];
int t;
int cu_zu[100003][2];
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            {scanf("%d",&a[i]);
        b[i]=a[i];
        }int z=0;
        sort(b+1,b+n+1);
        for(int i=1;i<=n;i++)
        {
            if(a[i]!=b[i])
            {
                for(int j=i+1;j<=n;j++)
                {
                    if(b[i]==a[j])
                    {
                        int t=a[j];
                        a[j]=a[i];
                        a[i]=t;
                        cu_zu[z][0]=i;
                        cu_zu[z++][1]=j;
                    }
                }
            }
        }
        printf("%d\n",z);
        for(int i=0;i<z;i++)
        {
            printf("%d %d\n",cu_zu[i][0],cu_zu[i][1]);
        }
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值