题意:给定一排列,让你通过一个区间交换的方式,完成排序。

析:这个题说了,最多不能超过20000次,而 n 最大才100,那么冒泡排序复杂度为 n * n,才10000,肯定是可以的,所以我们就模拟冒泡排序。

代码如下:

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <set>
#include <cstdio>
#include <cstring> using namespace std;
typedef long long LL;
const int maxn = 100 + 5;
int a[maxn];
int n; int main(){
scanf("%d", &n);
for(int i = 0; i < n; ++i) scanf("%d", &a[i+1]);
for(int i = 1; i < n; ++i)
for(int j = 1; j < n; ++j) if(a[j] > a[j+1]){
printf("%d %d\n", j, j+1);
swap(a[j], a[j+1]);
}
return 0;
}

CodeForces 686B Little Robber Girl's Zoo (构造冒泡排序)的更多相关文章

  1. codeforces 686B B. Little Robber Girl's Zoo(水题)

    题目链接: B. Little Robber Girl's Zoo //#include <bits/stdc++.h> #include <vector> #include ...

  2. 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 ...

  3. CodeForces 686B-Little Robber Girl's Zoo

    题目: 有n头数量的动物,开始它们站在一排,它们之间有高度差,所以需要将它们进行交换使得最终形成一个不减的序列,求它们交换的区间.交换的规则:一段区间[l, r]将l与l+1.l+2与l+3..... ...

  4. Educational Codeforces Round 7 D. Optimal Number Permutation 构造题

    D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...

  5. Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉

    Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  6. Codeforces 791C. Bear and Different Names 模拟构造

    C. Bear and Different Names time limit per test:1 second memory limit per test:256 megabytes input:s ...

  7. Codeforces Round #339 (Div. 1) C. Necklace 构造题

    C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...

  8. Codeforces - 814B - An express train to reveries - 构造

    http://codeforces.com/problemset/problem/814/B 构造题烦死人,一开始我还记录一大堆信息来构造p数列,其实因为s数列只有两项相等,也正好缺了一项,那就把两种 ...

  9. Codeforces Gym101341I:Matrix God(随机化构造矩阵降维)***

    http://codeforces.com/gym/101341/problem/I 题意:给三个N*N的矩阵,问a*b是否等于c. 思路:之前遇到过差不多的题目,当时是随机行(点),然后验证,不满足 ...

随机推荐

  1. MSMQ向远程服务器发送消息----错误总结

    一:路径错误(Path)错误 如果向远程服务器发送消息,请使用格式名的形式,如: FormatName:Direct=TCP:121.0.0.1\\private$\\queueFormatName: ...

  2. Tcl 和 Raft 发明人的软件设计哲学

    John Ousterhout(斯坦福大学教授,Tcl 语言.Raft 协议的发明人...真的是超级牛人,Title 好多好多,这里就列几个大家熟悉的),在 Google 做了一次演讲,题目就叫 「A ...

  3. 洛谷4294 [WC2008]游览计划——斯坦纳树

    题目:https://www.luogu.org/problemnew/show/P4294 大概是状压.两种转移,一个是以同一个点为中心,S由自己的子集拼起来:一个是S相同.中心不同的同层转移. 注 ...

  4. 判断网络类(获取mac) InternetCheck

    using System; using System.Collections.Generic; using System.Net.NetworkInformation; using System.Ru ...

  5. 关于 javascript:void(0) 的问题.

    原文地址:楚广明的博客 http://www.cnblogs.com/chu888chu888/archive/2012/01/05/2313045.html 最近看了好几个关于<a>标签 ...

  6. Log4j(3)--rootLogger根配置和appender输出类型配置

    参考博客:http://blog.java1234.com/blog/articles/270.html 一.rootLogger根配置: Log4j 根配置语法 log4j.rootLogger = ...

  7. Jenkins迁移

    Jenkins:http://192.168.1.240:8080/jenkins 重启jenkins: sudo /etc/init.d/jenkins start sudo /etc/init.d ...

  8. win和linux下控制台界面中停顿X秒的方式

    win localhost > nul linux

  9. sqoop导出到mysql中文乱码问题总结、utf8、gbk

    sqoop导出到mysql中文乱码问题总结.utf8.gbk 今天使用sqoop1.4.5版本的(hadoop使用cdh5.4)因为乱码问题很是头痛半天.下面进行一一总结 命令: [root@sdzn ...

  10. Python实践练习:将一个文件夹备份到一个 ZIP 文件

    题目 项目要求:假定你正在做一个项目,它的文件保存在 C:\AlsPythonBook 文件夹中.你担心工作会丢失, 所以希望为整个文件夹创建一个 ZIP 文件, 作为"快照" . ...