博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2299 归并排序求逆序数 (可做模板)
阅读量:4966 次
发布时间:2019-06-12

本文共 1471 字,大约阅读时间需要 4 分钟。

Time Limit: 7000MS   Memory Limit: 65536K
Total Submissions: 48077   Accepted: 17533

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

The input contains several test cases. Every test case begins with a line that contains a single integer n < 500,000 -- the length of the input sequence. Each of the the following n lines contains a single integer 0 ≤ a[i] ≤ 999,999,999, the i-th input sequence element. Input is terminated by a sequence of length n = 0. This sequence must not be processed.

Output

For every input sequence, your program prints a single line containing an integer number op, the minimum number of swap operations necessary to sort the given input sequence.

Sample Input

59105431230

Sample Output

60

Source

 

#include
#include
#include
#include
using namespace std;long long sum;int temp[500005];void sort2(int a[],int l,int mid,int r){ // memset(temp,0,sizeof(temp)); int i=l,j=mid+1,k=0; while(i<=mid&&j<=r){ if(a[i]

 

 

 

 

 

 

转载于:https://www.cnblogs.com/13224ACMer/p/4698765.html

你可能感兴趣的文章
安装tomcat
查看>>
【转载】Maven学习总结(三)——使用Maven构建项目
查看>>
db2pd 分析锁等待 步骤 --【监控】
查看>>
Linux使用系统光盘作为YUM源
查看>>
robotframework笔记16
查看>>
IE6 PNG透明终极解决方案(转载)
查看>>
添加一个Application Framework Service
查看>>
Python——字符转换(int , bool ,str)
查看>>
Mycat分表分库
查看>>
2019.7.11
查看>>
Php取扩展名
查看>>
模板的文件名和方法名一定要一致!!
查看>>
**p
查看>>
优先队列详解
查看>>
VS2012 创建项目失败,,提示为找到约束。。。。
查看>>
外观模式(Facade Pattern)
查看>>
BZOJ 1878: [SDOI2009]HH的项链( BIT )
查看>>
BZOJ 1007: [HNOI2008]水平可见直线( 计算几何 )
查看>>
C#编写window服务,一步一步(1)
查看>>
Uva(10986)
查看>>