| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 373 人关注过本帖, 1 人收藏
标题:计算逆序数的数目
取消只看楼主 加入收藏
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
结帖率:94.72%
收藏(1)
 问题点数:0 回复次数:0 
计算逆序数的数目
刚在csdn看到了这题, 记得这是偶以前出过的一题, 现在有网站翻新了, 哈哈。
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
5
9
1
0
5
4
3
1
2
3
0
Sample Output
6
0
搜索更多相关主题的帖子: 逆序 
2010-10-08 13:02
快速回复:计算逆序数的数目
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049194 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved