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

时间:2022-11-08 07:44:03

B. Little Robber Girl's Zoo

题目连接:

http://www.codeforces.com/contest/686/problem/B

Description

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.

Sample Input

4

2 1 4 3

Sample Output

1 4

Hint

题意

给你n个数,你需要把它变成非递减的序列

你每次操作可以给定一个[L,R]区间,使得这个区间的数l和l+1交换,l+2和l+3交换。。。R和R-1交换

然后最多输出20000次,使得有序。

题解:

为什么这么麻烦呢?操作

我每次只操作两个数不就好了,然后就像冒泡排序那样去写就好了。。。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 105;
int a[maxn],n;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=n;i>=1;i--){
for(int j=1;j<i;j++){
if(a[j]>a[j+1]){
swap(a[j],a[j+1]);
cout<<j<<" "<<j+1<<endl;
}
}
}
}

Codeforces Round #359 (Div. 2) B. Little Robber Girl's Zoo 水题的更多相关文章

  1. Codeforces Round &num;356 &lpar;Div&period; 2&rpar;B&period; Bear and Finding Criminals(水题)

    B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  2. Codeforces Round &num;343 &lpar;Div&period; 2&rpar; A&period; Far Relative’s Birthday Cake 水题

    A. Far Relative's Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/A Description Do ...

  3. Codeforces Round &num;385 &lpar;Div&period; 2&rpar; A&period; Hongcow Learns the Cyclic Shift 水题

    A. Hongcow Learns the Cyclic Shift 题目连接: http://codeforces.com/contest/745/problem/A Description Hon ...

  4. Codeforces Round &num;396 &lpar;Div&period; 2&rpar; A&period; Mahmoud and Longest Uncommon Subsequence 水题

    A. Mahmoud and Longest Uncommon Subsequence 题目连接: http://codeforces.com/contest/766/problem/A Descri ...

  5. Codeforces Round &num;375 &lpar;Div&period; 2&rpar; A&period; The New Year&colon; Meeting Friends 水题

    A. The New Year: Meeting Friends 题目连接: http://codeforces.com/contest/723/problem/A Description There ...

  6. Codeforces Round &num;258 &lpar;Div&period; 2&rpar; C&period; Predict Outcome of the Game 水题

    C. Predict Outcome of the Game 题目连接: http://codeforces.com/contest/451/problem/C Description There a ...

  7. Codeforces Round &num;358 &lpar;Div&period; 2&rpar; B&period; Alyona and Mex 水题

    B. Alyona and Mex 题目连接: http://www.codeforces.com/contest/682/problem/B Description Someone gave Aly ...

  8. 【打CF,学算法——二星级】Codeforces Round &num;313 &lpar;Div&period; 2&rpar; B&period; Gerald is into Art(水题)

    [CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/B 题面: B. Gerald is into Art time limit per t ...

  9. Codeforces Round &num;294 &lpar;Div&period; 2&rpar;A - A and B and Chess 水题

    A. A and B and Chess time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. ztree使用心得

    一个很好用的Jquery树形控件 官网:http://www.ztree.me/v3/main.php#_zTreeInfo 我主要引用的文件为: //最新版的JS压缩包 <script src ...

  2. cmake 学习笔记&lpar;六&rpar;

    希望这是现阶段阻碍阅读shiboken和PySide源码的涉及cmake的最后一个障碍 ^ _^ 学习 cmake 的单元测试部分 ctest. 简单使用 最简单的使用ctest的方法,就是在 CMa ...

  3. 【java】打印流的基本实现及java&period;io&period;PrintStream、java&period;io&period;PrintWriter示例

    package 打印流; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; impor ...

  4. Django&lowbar;form验证

    需求: 当用户向Django后端以post提交数据的时候,无论前端是否进行数据合法验证,后端都需要对客户端提交过来的数据进行数据合法性验证,是否可以利用models中表类字段的约束来实现验证,并且可以 ...

  5. yum工作原理

    yum工作原理 yum是一个RPM包的前端管理工具,在rpm包的依赖关系已经被建成数据库的前提下它能够实现自动查找相互依赖的人rpm包,并从repository中下载互相依赖的rpm包到本地. YUM ...

  6. C&num;4&period;5-4&period;7学习总结

    4.5讲的是this关键字.它用于表示对当前实例的引用,它有三种用法,一是访问属性,解决与局部变量名称冲突问题,二是访问成员方法,在类中调用自己的成员方法,就是在一个方法中,通过this.方法名,调用 ...

  7. bind 笔记

    BIND 的安装和配置: dns 服务,程序包名为bind ,程序名称为named 只需要安装 bind ,bind-libs ,bind-utils 生产环境全部安装 bind 服务脚本 :/etc ...

  8. BZOJ4259&colon; 残缺的字符串&lpar;FFT 字符串匹配&rpar;

    题意 题目链接 Sol 知道FFT能做字符串匹配的话这就是个裸题了吧.. 考虑把B翻转过来,如果\(\sum_{k = 0}^M (B_{i - k} - A_k)^2 * B_{i-k}*A_k = ...

  9. elasticsearch日志删除命令

    通过curl发送DELETE命令给elasticsearch服务器,进行日志删除操作.命令示例如下: curl -XDELETE *' curl -XDELETE 'http://192.168.10 ...

  10. 继承方法--&gt&semi;call继承

    function Person(name,age,sex){ this.name = name; this.age = age; this.sex = sex; }function P1(name,a ...