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

析:这个题说了,最多不能超过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. 系列文章--WF学习资料汇总

    学习WF当然是MSDN作为第一手材料,但是看完了一些基础的入门知识后,园子里的一些WF大牛们的系列文章就是很好的提高的材料了.在此,感谢他们,我真佩服他们有这样的耐心和良好的学习习惯. 以下就是我经常 ...

  2. centeros php 实战

    apache 默认安装路径 Fedora Core, CentOS, RHEL:ServerRoot              ::      /etc/httpdPrimary Config Fle ...

  3. IDEA java开发学习笔记

    JDK8下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 配置环境变量 ...

  4. VBA7种文档遍历法

    Sub 在选定文档最后加入一句话() '遍历文件 Dim MyDialog As FileDialog On Error Resume Next Application.ScreenUpdating ...

  5. F5 SNAT NAT相关

    SNAT: 跟路由器.防火墙一样,BIG-IP系统提供NAT (Network Address Translation)和SNAT(Secure Network Address Translation ...

  6. WebAPI认证与授权

    Web APi之认证(Authentication)及授权(Authorization)[一](十二) http://www.cnblogs.com/CreateMyself/p/4856133.ht ...

  7. oracle事务知识点小结

    DML语句流程 1 获取事务锁和ITL2 锁定候选行3 生成redo4 生成undo5 生成redo record写入log buffer并更改数据块 事务提交1 分配SCN2 更新事务表,将事务槽状 ...

  8. Spring Boot使用@Scheduled定时器任务

      摘要: Spring Boot之使用@Scheduled定时器任务 假设我们已经搭建好了一个基于Spring Boot项目,首先我们要在Application中设置启用定时任务功能@EnableS ...

  9. [Python] numpy.sum

    import numpy as np #Syntax: numpy.sum(a, axis=None, dtype=None, out=None, keepdims=<class numpy._ ...

  10. 使用http-proxy-middleware 代理跨域

    使用http-proxy-middleware 代理跨域 例如请求的url:“http://f.apiplus.cn/bj11x5.json” 1.打开config/index.js,在proxyTa ...