CodeForces 686B Little Robber Girl's Zoo (构造冒泡排序)
题意:给定一排列,让你通过一个区间交换的方式,完成排序。
析:这个题说了,最多不能超过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 (构造冒泡排序)的更多相关文章
- 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 686B-Little Robber Girl's Zoo
题目: 有n头数量的动物,开始它们站在一排,它们之间有高度差,所以需要将它们进行交换使得最终形成一个不减的序列,求它们交换的区间.交换的规则:一段区间[l, r]将l与l+1.l+2与l+3..... ...
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉
Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
- 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 ...
- Codeforces Round #339 (Div. 1) C. Necklace 构造题
C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...
- Codeforces - 814B - An express train to reveries - 构造
http://codeforces.com/problemset/problem/814/B 构造题烦死人,一开始我还记录一大堆信息来构造p数列,其实因为s数列只有两项相等,也正好缺了一项,那就把两种 ...
- Codeforces Gym101341I:Matrix God(随机化构造矩阵降维)***
http://codeforces.com/gym/101341/problem/I 题意:给三个N*N的矩阵,问a*b是否等于c. 思路:之前遇到过差不多的题目,当时是随机行(点),然后验证,不满足 ...
随机推荐
- java System.arrayCopy使用说明
java System.arrayCopy使用说明 java.lang.System.arraycopy() 方法复制指定的源数组的数组,在指定的位置开始,到目标数组的指定位置. 下面是 System ...
- Linux vnc服务器操作(启动/停止/重起/自启动)
8.启动和停止VNC服务1)启动VNC服务命令[root@testdb ~]# /etc/init.d/vncserver startStarting VNC server: 1:rootNew 't ...
- 善待Erlang 代码 -- Xref 实践
Xref 是一个交叉引用工具,通过分析定义的函数间的调用关系,用于查找函数. 模块. 应用程序和版本之间的依赖关系. 通俗而言,Xref 可以检查代码中函数的调用关系.比如在 moduleA 中的 f ...
- MapBuilder,操作集合工具类
public class MapBuilder { /** * Creates an instance of {@code HashMap} */ public static <K, V> ...
- Java 运用流传输文件
实例1 package IO; import java.io.FileReader; import java.io.FileWriter; import java.io.Reader; import ...
- [html][LigerUI]使用示例
<link href="Source/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet&quo ...
- MyBatis框架简介
1.下载地址:下载地址:https://github.com/mybatis/mybatis-3/releases 2.MyBatis是什么? MyBatis 本是apache的一个开源项目iBati ...
- layui 弹框
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&q ...
- YII cookie和session的使用方法
设置cookie://首先新建cookie$cookie = new CHttpCookie(‘mycookie’, ‘this is my cookie’);//定义cookie的有效期$cooki ...
- 当前触发事件的两种方式(onclick) 和 ('id') 获取
1. <input type='text' onclick = 'Clickon(this)'> <script> function Clickon(num){ num.sty ...