Codeforces Round #359 (Div. 2) B
2 seconds
256 megabytes
standard input
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.
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.
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.
4
2 1 4 3
1 4
7
36 28 57 39 66 69 68
1 4
6 7
5
1 2 1 2 1
2 5
3 4
1 4
1 4
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的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #359 (Div. 1)
A http://codeforces.com/contest/685/standings 题意:给你n和m,找出(a,b)的对数,其中a满足要求:0<=a<n,a的7进制的位数和n-1的 ...
- 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 ...
- Codeforces Round #359 (Div. 1) A. Robbers' watch 暴力
A. Robbers' watch 题目连接: http://www.codeforces.com/contest/685/problem/A Description Robbers, who att ...
- 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 ...
- 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 ...
- Codeforces Round #359 (Div. 2) C. Robbers' watch 搜索
题目链接:http://codeforces.com/contest/686/problem/C题目大意:给你两个十进制的数n和m,选一个范围在[0,n)的整数a,选一个范围在[0,m)的整数b,要求 ...
- Codeforces Round #359(div 2)
A:= v = B:^ w ^ C:一天n个小时,一个小时m分(n,m十进制),一个手表有两部分,左边表示时,右边表示分,但都是7进制,而且手表上最多只能有7个数字且数字不能重复,现在要你算出能正确表 ...
- 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 ...
随机推荐
- 文件权限管理命令chmod,chown与文本搜索命令grep
1.复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限. [root@bogon home]# cp -r /etc/sk ...
- ethereum(以太坊)(十一)--字节数组(二)
pragma solidity ^0.4.0; contract test { uint [5] T =[1,2,3,4,5] ;//固定长度的数组:可修改数组内值大小,不支持push,不可更改长度 ...
- 判断移动端和pc端最简单的方法
<!DOCTYPE html><html><head> <title></title> <script type="text ...
- SSO 单点登录总结(PHP)
本篇文章根据个人理解的知识整理汇总,如有不足之处,请大家多多指正. 单点登录(SSO--Single Sign On)的应用是很普遍的,尤其在大型网站系统中,比如百度,登录百度账号和,再转到百度经验. ...
- 嵌入式Linux编译内核步骤 / 重点解决机器码问题 / 三星2451
嵌入式系统更新内核 1. 前言 手里有一块Friendly ARM的MINI2451的板子,这周试着编译内核,然后更新一下这个板子的Linux内核,想要更新Linux Kernel 4.1版本,但是种 ...
- Python全栈day 06
Python全栈day 06 一.数据类型补充完整 1. 列表(list) 反转reverse list1 = [1,2,3,4,5,6,7,8,9] list1.reverse() print(li ...
- POJ:3190-Stall Reservations
传送门:http://poj.org/problem?id=3190 Stall Reservations Time Limit: 1000MS Memory Limit: 65536K Total ...
- Ubuntu下配置LAMP + PhpStorm
本文仅作为一个记录,以下配置在Ubuntu 14.10 64-bit上验证通过. 安装Apache 2:sudo apt-get install apache2 安装成功能够后,通过浏览器访问loca ...
- 如何在一个顶级域名下用两个二级域名访问vps下的两个项目网站--完美解决骗
本人是原址是http://www.webzhe.com/server/340 后经过本人的实践修改,增加截图,等具体的步骤,完美解决 如何在vps中设置二级域名开通子网站,这个问题涉及到两步:一首先要 ...
- PowerShell脚本授权最佳实践
[TechTarget中国原创] Windows PowerShell已成为微软在Windows Server上提供的首选管理界面.因为深度整合到Windows Server操作系统,PowerShe ...