Ultra-QuickSort【归并排序典型题目】
| Time Limit: 7000MS | Memory Limit: 65536K | |
| Total Submissions: 34470 | Accepted: 12382 |
Description
In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascending order. For the input sequence 9 1 0 5 4 ,
Ultra-QuickSort produces the output
0 1 4 5 9 .
Your task is to determine how many swap operations Ultra-QuickSort needs to perform in order to sort a given input sequence.
Input
Output
Sample Input
5
9
1
0
5
4
3
1
2
3
0
Sample Output
6
0
Source
#include<iostream>
#include<string.h>
#include<cstdio>
#include<cstdlib>
#define max 1000000
using namespace std;
int n,f[max],g[max];
long long int sum=;
void guibing(int l,int mid,int r)
{
int t=;
int i=l,j=mid+;
while(i<=mid&&j<=r)
{
if(f[i]<=f[j])
{
g[t++]=f[i];
i++;
}
else
{
g[t++]=f[j];
j++;
sum=sum+mid-i+;
}
}
while(i<=mid)g[t++]=f[i++];
while(j<=r)g[t++]=f[j++];
for(i=;i<t;i++)
f[l+i]=g[i];
}
void quicksort(int l,int r)
{
if(l<r)
{
int mid=(l+r)/;
quicksort(l,mid);
quicksort(mid+,r);
guibing(l,mid,r);
}
}
int main()
{
while()
{
cin>>n;
if(n==)break;
int i;
sum=;
for(i=;i<=n-;i++)
cin>>f[i];
quicksort(,n-);
cout<<sum<<endl;
}
return ;
}
Ultra-QuickSort【归并排序典型题目】的更多相关文章
- MySQL基础练习---牛客网的数据以及典型题目
1 部门表departments 部门no和部门名称 2 部门员工表 dept_emp 每个部门对应的员工信息 3 部门经理表 dept_manager 每个部门的经理信息 4 员工表 employe ...
- (PMP)解题技巧和典型题目分析(每日20题)
3.11 1.A(C),2.D,3.A,4.B,5.A(C),6.D(A),7.D,8.A(D),9.B,10.D(B), 11.C(B),12.C(D),13.B,14.D,15.C,16.C(D) ...
- (PMP)解题技巧和典型题目分析(模拟二)
- (PMP)解题技巧和典型题目分析(模拟一)
- (PMP)解题技巧和典型题目分析(0903-3班)
B.项目有依赖 D A A B B C B C D B A B B A B
- (PMP)解题技巧和典型题目分析(0903-2班)
1.计算题 ,5 2.概念题,少 3.情景题,很多 C B C D ------------------------------------------------------------------ ...
- MySQL索引面试题分析(索引分析,典型题目案例)
[建表语句] create table test03( id int primary key not null auto_increment, c1 char(10), c2 char(10), c3 ...
- leetcode数组典型题目小结
数组与矩阵 数组与矩阵的基本知识: 1.数组:数组是在程序设计中,为了处理方便, 把具有相同类型的若干元素按有序的形式组织起来的一种形式. 首先,数组会利用索引来记录每个元素在数组中的位置,且在大多数 ...
- LeetCode:链表专题
链表专题 参考了力扣加加对与链表专题的讲解,刷了些 leetcode 题,在此做一些记录,不然没几天就没印象了 出处:力扣加加-链表专题 总结 leetcode 中对于链表的定义 // 定义方式1: ...
随机推荐
- linux 文件系统sysvinit 流程分析
参考网上许多的教程. 然后有一下相关的笔记: kernel 在挂载完文件系统后,会执行第一个进程init 这个进程的PID为1 这个进程是所有进程的父进程 init 进程,首先要去读取inittab中 ...
- js之词法分析
词法分析 词法分析: 先分析参数: 再分析变量声明: 分析函数声明: 一个函数能使用的局部变量,就从上面的3步分析而来 具体步骤: 1.函数运行前的一瞬间,生成 Active Object(活动对象) ...
- Linux下端口被占用解决
有时候关闭软件后,后台进程死掉,导致端口被占用.下面以JBoss端口8083被占用为例,列出详细解决过程. 解决方法: 1.查找被占用的端口 netstat -tln netstat -tln | ...
- jquery为新增元素添加事件
<script type="text/javascript"> var $id=1; $(function(){ $(".hehe").click( ...
- apache2错误日志在哪,可以看到php错误
在以下路径中 /var/log/apache2/error.log
- MySQL一次插入多行数据
CREATE TABLE `viewhistory` ( `viewid` ) NOT NULL AUTO_INCREMENT, `uid` ) NOT NULL, `video` ) NOT NUL ...
- iOS 中 为UIView添加背景图片
创建UIImage的方法有两种: UIImage *image = [UIImageimageNamed:@"image.jpg"];//这种不释放内存,要缓存 NSString ...
- IN和EXISTS的详解
从效率来看: 1) select * from T1 where exists(select 1 from T2 where T1.a=T2.a) ; T1数据量小而T2数据量非常大时,T1<& ...
- jq鼠标隐藏显示的方法
<div style="width:300px; float:left;"> <div onmouseover="testOnmouseO ...
- 数位DP题目汇总
Google Code Jam 2014 Round 1B Problem B hdu 2089 hdu 3555 uestc 250 (原1307) hdu 3652 hdu 3709 Light ...