文件名称:TextFile1
-
所属分类:
- 标签属性:
- 上传时间:2013-06-03
-
文件大小:764byte
-
已下载:0次
-
提 供 者:
-
相关连接:无下载说明:别用迅雷下载,失败请重下,重下不扣分!
介绍说明--下载内容来自于网络,使用问题请自行百度
该题要求读入n个整数,然后输出该n个整数的中位数。同时输入的数的个数是奇数的时候,中位数是唯一的;当输入的数是个数是是偶数的时候,求两个中位数的平均值,然后下取整输出。
一般来说,我们可以将这些数存在数组当中,然后对数组进行排序,最后利用数组下标查找即可。但也可以不排序找到中位数。毕竟排序是将所有数都放在合适的位置上,而查找中位数的操作只需要将中位数放在合适的位置即可。
下面就是不排序查找中位数的版本。事实上,下述解法其实是快速排序的一个变种。在n为奇数的情况下,下述代码运行时间较快排实现运行时间段,因为它每次将数组分成两部分之后只处理了其中一部分。-The questions require read n integers and then outputs the median of n integers. The number of simultaneous input number is odd, when the median is unique when the input number is the number that is even in the time of two of the median average and then rounded down output. In general, we can use these numbers exist among the array, and then sort the array, and finally look to take advantage of the array subscr ipt. But can not sort to find the median. After all, all the numbers are sorted is the right place, while the median lookup operation simply the median in the right location. Find below the median is not the sort version. In fact, the following solution is actually a variant of quicksort. In the case where n is odd, the following run-time code to achieve rapid discharge operation time, since it is divided into two parts each time the array is processed only after a part of it.
一般来说,我们可以将这些数存在数组当中,然后对数组进行排序,最后利用数组下标查找即可。但也可以不排序找到中位数。毕竟排序是将所有数都放在合适的位置上,而查找中位数的操作只需要将中位数放在合适的位置即可。
下面就是不排序查找中位数的版本。事实上,下述解法其实是快速排序的一个变种。在n为奇数的情况下,下述代码运行时间较快排实现运行时间段,因为它每次将数组分成两部分之后只处理了其中一部分。-The questions require read n integers and then outputs the median of n integers. The number of simultaneous input number is odd, when the median is unique when the input number is the number that is even in the time of two of the median average and then rounded down output. In general, we can use these numbers exist among the array, and then sort the array, and finally look to take advantage of the array subscr ipt. But can not sort to find the median. After all, all the numbers are sorted is the right place, while the median lookup operation simply the median in the right location. Find below the median is not the sort version. In fact, the following solution is actually a variant of quicksort. In the case where n is odd, the following run-time code to achieve rapid discharge operation time, since it is divided into two parts each time the array is processed only after a part of it.
(系统自动生成,下载前可以参看下载内容)
下载文件列表
TextFile1.txt
本网站为编程资源及源代码搜集、介绍的搜索网站,版权归原作者所有! 粤ICP备11031372号
1999-2046 搜珍网 All Rights Reserved.