#include <iostream>
#include <bits/stdc++.h>
using namespace std; typedef long long ll; //int sum = 0;
int a[100004]; //题目是长整型,不过这里 int 也可以。。
int b[100005]; void qusort(int l, int r, int a[], int &sum) //这里如果不想传sum,就把sum定义成全局,如注释
{
int i = l, j = r;
int x = a[i];
if(i >= j) return ;
while(i < j)
{
while(i < j && a[j] >= x) j --;
if(a[j] != a[i]) sum ++;
a[i] = a[j];
while(i < j && a[i] <= x) i ++;
if(a[j] != a[i]) sum ++;
a[j] = a[i];
}
a[i] = x;
qusort(l,i-1,a,sum);
qusort(i+1,r,a,sum);
}
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i = 0; i < n; i ++)
{
scanf("%d",&a[i]);
b[i] = a[i];
}
int num = 0; // 冒泡
int sum = 0; //快排 for(int i = 0; i < n; i ++)
{
for(int j = 0; j < n - i - 1; j ++)
{
if(a[j] > a[j +1])
{
int t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
num ++;
}
}
}
qusort(0,n-1,b,sum);
printf("%d %d\n",num,sum);
}
return 0;
}

数据结构实验之排序二:交换排序 (SDUT 3399)的更多相关文章

  1. SDUT 3399 数据结构实验之排序二:交换排序

    数据结构实验之排序二:交换排序 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 冒泡排序和快 ...

  2. SDUT OJ 数据结构实验之排序二:交换排序

    数据结构实验之排序二:交换排序 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...

  3. SDUT-3399_数据结构实验之排序二:交换排序

    数据结构实验之排序二:交换排序 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 冒泡排序和快速排序都是基于"交 ...

  4. SDUT 3401 数据结构实验之排序四:寻找大富翁.!

    数据结构实验之排序四:寻找大富翁 Time Limit: 150MS Memory Limit: 512KB Submit Statistic Problem Description 2015胡润全球 ...

  5. SDUT OJ 数据结构实验之二叉树二:遍历二叉树

    数据结构实验之二叉树二:遍历二叉树 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...

  6. SDUT OJ 数据结构实验之串二:字符串匹配

    数据结构实验之串二:字符串匹配 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...

  7. SDUT OJ 数据结构实验之排序四:寻找大富翁

    数据结构实验之排序四:寻找大富翁 Time Limit: 200 ms Memory Limit: 512 KiB Submit Statistic Discuss Problem Descripti ...

  8. SDUT OJ 数据结构实验之排序三:bucket sort

    数据结构实验之排序三:bucket sort Time Limit: 250 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem D ...

  9. SDUT OJ 数据结构实验之排序一:一趟快排

    数据结构实验之排序一:一趟快排 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...

随机推荐

  1. Java 枚举和抽象类添加状态值

    枚举: public enum CourseTypeEnum { VIDEO_COURSE(1,"录制课程"), LIVE_COURSE(2,"直播课程"), ...

  2. Windows中的消息与消息队列

    消息 在Windows中,消自由MSG结构体表示 typedef struct tagMSG { HWND hwnd; UINT message; WPARAM wParam; LPARAM lPar ...

  3. easyui-datagrid清空表中原有数据

    $('#dg').datagrid('loadData', { total: 0, rows: [] });

  4. it commit提示Your branch is up-to-date with 'origin/master'.

    今天提交git仓库的时候,遇到了如截图所示的问题,提示Your branch is up-to-date with 'origin/master'. 查了些资料后,发现其根本原因是版本分支的问题 这时 ...

  5. 方便前端使用的SVG雪碧图

    更多代码详情:github.crmeb.net/u/LXT 简介 由于SVG自身的矢量性质,不管在什么情况下,图标都很清晰,可以适应不同尺寸大小和不同分辨率.不用担心模糊和锯齿.同时还能更改图标的填充 ...

  6. C++遍历磁盘驱动器

    #include <stdio.h> #include <windows.h> typedef struct tagDRIVER { // (1)磁盘盘符 wchar_t di ...

  7. Qt QListWidget

    以下代码是 List Widget 添加数据项的代码,一般放在构造函数即可. /*********************添加数据项*********************/ QIcon icon1 ...

  8. iOS pushViewController 和 presentViewController的区别 详解

    pushViewController 导航控制器入栈的方式切换页面presentViewController 模态切换的方式切换页面 1:用 UINavigationController 的时候用 p ...

  9. WebStorm 2019激活方法

    1.先下载安装JetBrains WebStorm 2019,安装完成先不要运行2.接下来对软件进行注册破解,首先以记事本的方式打开hosts文件,将代码添加至hosts文件屏蔽软件联网:hosts文 ...

  10. mysql学习之基础篇06

    子查询:又分为where型子查询,from型子查询,exists型子查询这三类. where型子查询:指把内层查询的结果作为外层查询的比较条件: 举个例子: 我们想查出goods_id最大的商品,要求 ...