B. Little Robber Girl's Zoo
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.

The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.

Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo.

The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.

Output

Print the sequence of operations that will rearrange the animals by non-decreasing height.

The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li < ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed.

The number of operations should not exceed 20 000.

If the animals are arranged correctly from the start, you are allowed to output nothing.

Examples
Input
4
2 1 4 3
Output
1 4
Input
7
36 28 57 39 66 69 68
Output
1 4
6 7
Input
5
1 2 1 2 1
Output
2 5
3 4
1 4
1 4
Note

Note that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed

题意:给你一段序列  一种 操作 在【l,r】区间上(l-r+1为偶数)swap(l,l+1),swap(l+2,l+3).....

最终使得序列为非递减序列  输出操作流程

题解;不要求操作步骤最少,所以可以考虑区间长度都为2的操作  找到最小的值不断交换向前移动

 #include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define ll __int64
#define pi acos(-1.0)
using namespace std;
ll n;
ll a[];
ll minx;
ll minpos;
int main()
{
scanf("%I64d",&n);
for(int i=;i<=n;i++)
{
scanf("%I64d",&a[i]);
}
for(int i=;i<=n;i++)
{
minx=;
minpos=;
for(int j=i;j<=n;j++)
{
if(a[j]<minx)
{
minx=a[j];
minpos=j;
}
}
for(int k=minpos;k>=i+;k--)
{
swap(a[k],a[k-]);
printf("%d %d\n",k-,k);
}
}
return ;
}

Codeforces Round #359 (Div. 2) B的更多相关文章

  1. Codeforces Round #359 (Div. 2)C - Robbers' watch

    C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  2. Codeforces Round #359 (Div. 2) C. Robbers' watch (暴力DFS)

    题目链接:http://codeforces.com/problemset/problem/686/C 给你n和m,问你有多少对(a, b) 满足0<=a <n 且 0 <=b &l ...

  3. Codeforces Round #359 (Div. 1)

    A http://codeforces.com/contest/685/standings 题意:给你n和m,找出(a,b)的对数,其中a满足要求:0<=a<n,a的7进制的位数和n-1的 ...

  4. Codeforces Round #359 (Div. 1) B. Kay and Snowflake dfs

    B. Kay and Snowflake 题目连接: http://www.codeforces.com/contest/685/problem/B Description After the pie ...

  5. Codeforces Round #359 (Div. 1) A. Robbers' watch 暴力

    A. Robbers' watch 题目连接: http://www.codeforces.com/contest/685/problem/A Description Robbers, who att ...

  6. Codeforces Round #359 (Div. 2) B. Little Robber Girl's Zoo 水题

    B. Little Robber Girl's Zoo 题目连接: http://www.codeforces.com/contest/686/problem/B Description Little ...

  7. Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题

    A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...

  8. Codeforces Round #359 (Div. 2) C. Robbers' watch 搜索

    题目链接:http://codeforces.com/contest/686/problem/C题目大意:给你两个十进制的数n和m,选一个范围在[0,n)的整数a,选一个范围在[0,m)的整数b,要求 ...

  9. Codeforces Round #359(div 2)

    A:= v = B:^ w ^ C:一天n个小时,一个小时m分(n,m十进制),一个手表有两部分,左边表示时,右边表示分,但都是7进制,而且手表上最多只能有7个数字且数字不能重复,现在要你算出能正确表 ...

  10. Codeforces Round #359 (Div. 2) D. Kay and Snowflake 树DP

    D. Kay and Snowflake     After the piece of a devilish mirror hit the Kay's eye, he is no longer int ...

随机推荐

  1. laravel EncryptCookies中间件导致无法获取自定义cookie

    解决办法: \app\Http\Middleware\EncryptCookies.php 添加过滤cookie key protected $except = [ 'token' ];

  2. day1_作业2(三级菜单)

    #!/usr/local/bin/python3 # -*- coding:utf-8 -*- province={'江苏省':['南京市','苏州市','无锡市'],'浙江省':['杭州市','温州 ...

  3. L2-032 彩虹瓶 (25 分)

    L2-032 彩虹瓶 (25 分)   彩虹瓶的制作过程(并不)是这样的:先把一大批空瓶铺放在装填场地上,然后按照一定的顺序将每种颜色的小球均匀撒到这批瓶子里. 假设彩虹瓶里要按顺序装 N 种颜色的小 ...

  4. 12-optionBinding

    1-创建一个空的dotnet mvc网站 2- 创建appsettings.json文件, 这文件会默认被绑定 { "ClassNo": "1", " ...

  5. Oozie 之 sqoop 实战

    1.创建 lib 目录并拷贝 mysql 支持包 2.修改 job.properties 文件 nameNode=hdfs://cen-ubuntu.cenzhongman.com:8020 jobT ...

  6. 20,Django contenttypes 应用

    contenttypes 是Django内置的一个应用,可以追踪项目中所有app和model的对应关系,并记录在ContentType表中. 1.创建一个项目 2.数据库迁移,生成默认表. 3.存着所 ...

  7. div+css实现双飞翼布局

    本例通过div+css实现HTML金典布局双飞翼布局,该布局结构为上中下结构,上:header头:下:footer尾:中:内容,将内容分为了三个结构,左中右 下图是效果图 我们来看下代码 <!D ...

  8. HDU 5293 Tree chain problem 树形DP

    题意: 给出一棵\(n\)个节点的树和\(m\)条链,每条链有一个权值. 从中选出若干条链,两两不相交,并且使得权值之和最大. 分析: 题解 #include <cstdio> #incl ...

  9. android stadio 快捷键最好的材料 android stadio大全 最牛逼的android stadio快捷键

    一: .nn .if .for .toast .instanceof .switch 这些都是可以直接点的,一个变量然后.for ,如果这个这个变量是个集合,都可以.for 二: 关闭所有窗口 ctr ...

  10. Hbase物理存储

    物理模型 每个column family存储在HDFS上的一个单独文件中,空值不会被保存. Key 和 Version number在每个column family中均有一份: HBase为每个值维护 ...