題目描述:
我們對 0 到 255 之間的整數進行取樣,並將結果儲存在陣列 count 中:count[k] 就是整數 k 的取樣個數。
我們以 浮點數 陣列的形式,分別返回樣本的最小值、最大值、平均值、中位數和眾數。其中,眾數是保證唯一的。
我們先來回顧一下中位數的知識:
如果樣本中的元素有序,並且元素數量為奇數時,中位數為最中間的那個元素;
如果樣本中的元素有序,並且元素數量為偶數時,中位數為中間的兩個元素的平均值。
示例 1:
輸入:count = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
輸出:[1.00000,3.00000,2.37500,2.50000,3.00000]
示例 2:
輸入:count = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
輸出:[1.00000,4.00000,2.18182,2.00000,1.00000]
count.length == 256
1 <= sum(count) <= 10^9
計數表示的眾數是唯一的
答案與真實值誤差在 10^-5 以內就會被視為正確答案
方法1:
(1)一遍遍歷中獲得最大值,最小值,眾數,總的數字數量和總的數字數量和;
(2)然後再單獨找出中位數,根據總的數量是奇數還是偶數,確定中位數;
class
solution
max_v=i;
//確定最大值
counts+
=count[i]
;//確定總的數字數量
sum_all+
=count[i]
*i;//確定總的數字數量和
if(count[i]
>mode_v)}}
double mid_v;
//確定中位數
if(counts&1)
mid-
=count[i];}
mid_v=mid;
//中位數
}else
left=i;
++i;
while
(count[i]==0
) right=i;
break;}
left-
=count[i];}
mid_v=
(left+right)
/2.0
;//中位數
}return;}
};
樣本和統計量
1.樣本空間 隨機試驗 e 的所有基本結果組成的集合為 e 的 樣本空間。樣本空間中的資料元素具有唯一性,不能重複。2.總體 所研究物件的某項數量指標取值的全體稱為總體,用隨機變數 x 表示。比如我們要研究亞洲人的身高分布,那所有亞洲人的身高資料就構成 總體。總體中資料個數大於等於樣本空間中的資料個...
css2三大樣式表
html標籤可以分為幾種型別 按照是否換行來分 行級元素 行內元素,不會獨佔一行 塊級元素 塊元素,獨佔一行 根據是否閉合來分 完全閉合 自閉和 單閉合 屬性 值 顏色值 取值型別 1.單詞值,red。2.十六進製制顏色值,000000 3.rgb,rgb 114,255,255 rgba 114,...
學習筆記 概率統計 統計總體與樣本
從概率論到數理統計 經典統計學的推斷過程 設 x 1,x 2,cdots,x n 為來自總體 x 的乙個樣本 若 x i 來自樣本的觀察值,以上計算結果也稱為對應樣本矩的觀察值 設 x 1,x 2,cdots,x n 為來自總體 x 的乙個樣本,g x 1,x 2,cdots,x n 是乙個不含有其...