CodeForces 686B-Little Robber Girl's Zoo
题目:
有n头数量的动物,开始它们站在一排,它们之间有高度差,所以需要将它们进行交换使得最终形成一个不减的序列,求它们交换的区间.
交换的规则:一段区间[l, r]将l与l+1、l+2与l+3、...、r-1与r交换.
分析:
因为n不超过100,最多的交换次数为(100-1)*(100-1)<10000(序列最坏的情况),不会超过20000;因此可以不用合并,即可以不用将区间[1,2],[3,4]合并为[1,4].采用冒泡排序就可以解决.
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <ctime>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <iterator>
#include <vector> using namespace std; #define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 10000010
#define MAXM 1000010 const int maxn = ;
LL a[maxn]; int main()
{
int n;
int ans;
int pos, flag;
while(scanf("%d", &n)==)
{
int x, y;
ans = ;
int i, j;
for(i = ; i < n; i++ )
scanf("%lld", &a[i]);
for(i = ; i < n-; i++ )
{
flag = ;
pos = ;
x = ;
y = ;
for(j = ; j < n--i; j++ )
{
if(a[j] > a[j+])
{
flag = ;
pos++;
if(pos == )
{
x = j;
y = j+;
}
else
{
if(j - y == )
y = j+;
else if(j - y >= )
{
printf("%d %d\n", x+, y+);
x = j;
y = j+;
}
}
int temp;
temp = a[j];
a[j] = a[j+];
a[j+] = temp;
//printf("%d %d\n", j+1, j+2);
}
}
if(flag)
printf("%d %d\n", x+, y+);
}
} return ;
}
CodeForces 686B-Little Robber Girl's Zoo的更多相关文章
- CodeForces 686B Little Robber Girl's Zoo (构造冒泡排序)
题意:给定一排列,让你通过一个区间交换的方式,完成排序. 析:这个题说了,最多不能超过20000次,而 n 最大才100,那么冒泡排序复杂度为 n * n,才10000,肯定是可以的,所以我们就模拟冒 ...
- codeforces 686B B. Little Robber Girl's Zoo(水题)
题目链接: B. Little Robber Girl's Zoo //#include <bits/stdc++.h> #include <vector> #include ...
- 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 437 D. The Child and Zoo 并查集
题目链接:D. The Child and Zoo 题意: 题意比较难懂,是指给出n个点并给出这些点的权值,再给出m条边.每条边的权值为该条路连接的两个区中权值较小的一个.如果两个区没有直接连接,那么 ...
- codeforces 686B
题意:给出一个序列,只允许进行相邻的两两交换,给出使序列变为非降序列的操作方案. 思路:关键点是操作次数不限,冒泡排序. #include<iostream> #include<cs ...
- 套题 codeforces 359
A题:Free Ice Cream 注意要使用LL,避免爆int #include <bits/stdc++.h> #define scan(x,y) scanf("%d%d&q ...
- Codeforces Round #359 div2
Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...
- Codeforces Round #359 (Div. 2) B
B. Little Robber Girl's Zoo time limit per test 2 seconds memory limit per test 256 megabytes input ...
- codeforces29A
Spit Problem CodeForces - 29A In a Berland's zoo there is an enclosure with camels. It is known that ...
随机推荐
- 25条提高iOS app性能的方法和技巧
以下这些技巧分为三个不同那个的级别---基础,中级,高级. 基础 这些技巧你要总是想着实现在你开发的App中. 1. 用ARC去管理内存(Use ARC to Manage Memory) 2.适当的 ...
- Mssql Server如何修改列名
exec sp_rename '表明.原列名','新列名','column';
- 批处理命令——if
[1]if命令简介 if,大家肯定见多了,一个没有用过if的程序员不是一个好产品经理(呵呵~~). if,判断选择的作用,自从写了几年代码,我才真正弄明白了一件事,为什么当初上学时候考试总要做那么多的 ...
- android中ContentProvider获取联系人 总结
35.内容提供者:ContentResolver 用内容提供者来获取联系人信息 35-1:权限 <!-- 对联系人的读.写权限 --> <uses-permission androi ...
- Tomcat 发布war包提示war包超出大小修改
error信息: java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$Size ...
- QA、Selenium WebDriver (Q&A)
Q:启动IE浏览器时突然报下面错误,不能正常使用. WebDriverException: Message: Unexpected error launching Internet Explo ...
- [问题2014S03] 复旦高等代数II(13级)每周一题(第三教学周)
[问题2014S03] 设 \(A\in M_n(\mathbb R)\) 是非异阵并且 \(A\) 的 \(n\) 个特征值都是实数. 若 \(A\) 的所有 \(n-1\) 阶主子式之和等于零, ...
- Java中byte与16进制字符串的互相转换
* Convert byte[] to hex string.这里我们可以将byte转换成int,然后利用Integer.toHexString(int)来转换成16进制字符串. * @param s ...
- h-ui前端框架
h-ui.net
- 微信小程序注册app
App() App() 函数用来注册一个小程序.接受一个 object 参数,其指定小程序的生命周期函数等. object参数说明 onLaunch Function 生命周期函数--监听小程序初 ...