Skip to content

Latest commit

 

History

History
57 lines (37 loc) · 1.93 KB

Ex_1_1_34.md

File metadata and controls

57 lines (37 loc) · 1.93 KB
title date draft tags categories
算法4 Java解答 1.1.34
2019-03-02 19:38:48 +0800
false
JAVA
技术
归档

1.1.34

问题:

Filtering.

Which of the following require saving all the values from standard input (in an array, say), and which could be implemented as a filter using only a fixed number of variables and arrays of fixed size (not dependent on N)? For each, the input comes from standard input and consists of N real numbers between 0 and 1.

分析:

Print the maximum and minimum numbers
two variables

Print the median of the numbers
median中位数
中位数是通过排序得到的,它不受最大、最小两个极端数值的影响。部分数据的变动对中位数没有影响,当一组数据中的个别数据变动较大时,常用它来描述这组数据的集中趋势。
对于一组有限个数的数据来说,它们的中位数是这样的一种数:这群数据里的一半的数据比它大,而另外一半数据比它小。 计算有限个数的数据的中位数的方法是:把所有的同类数据按照大小的顺序排列。如果数据的个数是奇数,则中间那个数据就是这群数据的中位数;如果数据的个数是偶数,则中间那2个数据的算术平均值就是这群数据的中位数。
中位数:也就是选取中间的数,是一种衡量集中趋势的方法。

Print the k th smallest value, for k less than 100
needs array of size 100

1. 使用排序方法。例如,使用冒泡排序,外层K次。需要保存所有值。

2. 使用大顶堆,size为K。输出最小值即可。需要size为K的数组。


Print the sum of squares of the numbers
fixed number of variables

Print the percentage of numbers greater than the average
require saving all the values

Print the N numbers in increasing order.
size为N的数组,升序排列输出。

Print the N numbers in random order.
require saving all the values

参考: