51NOD 資料流中的演算法

2022-04-30 04:18:10 字數 1192 閱讀 7801

【演算法】數學

【題解】

1.平均數:累加字首和。//聽說要向下取整?

2.中位數:雙堆法,大於中位數存入小頂堆,小於中位數存入大頂堆,保證小頂堆內數字數量≥大頂堆,奇數則取小堆頂,偶數則取兩堆頂/2。

3.方差=(平方的均值)-(均值的平方),即對於a,b,c,s2=(a2+b2+c2)/3-((a+b+c)/3)2。

#include#include

#include

#include

#include

using

namespace

std;

const

int maxn=1000010

;multiset

q2;//

小頂堆

struct

cmp};

multiset

q1;//

大頂堆

intn,k,a[maxn],sum[maxn],tot1,tot2;

long

long

sums[maxn];

double

ans2;

intread()

while(isdigit(c=getchar()));

return s*t;

}void

compair()

if(tot2-1>tot1)

if((tot1+tot2)%2

) ans2=*q2.begin();

else ans2=1.0*(*q1.begin()+*q2.begin())/2;}

intmain()

sum[tot]=sum[tot-1]+a[tot];

if(a[tot]>=ans2)q2.insert(a[tot]),tot2++;

else q1.insert(a[tot]),tot1++;

compair();

sums[tot]=sums[tot-1]+a[tot]*a[tot];

}else

if(task==2

)

else

if(task==4

)

else

if(task==3

)

}return0;

}

view code

51Nod 1785 資料流中的演算法

1785 資料流中的演算法 基準時間限制 1.5 秒 空間限制 131072 kb 分值 20 難度 3級演算法題 51nod近日上線了使用者滿意度檢測工具,使用高階人工智慧演算法,通過使用者訪問時間 滑鼠軌跡等特徵計算使用者對於 的滿意程度。現有的統計工具只能統計某乙個視窗中,使用者的滿意程度的均...

51nod 1785 資料流中的演算法

這題看了好多遍,才看懂題目中k的意思,k就是每次計算最多只能到k個人 坑點是平均數那裡,在計算平均數的時候,輸出平均數的時候要向下取整,然後輸出的時候還要保留兩位小數,然而計算方差的時候,那個平均數就不能向下取整了,否則就錯了。include include include const int ma...

51nod 1785 資料流中的演算法

51nod近日上線了使用者滿意度檢測工具,使用高階人工智慧演算法,通過使用者訪問時間 滑鼠軌跡等特徵計算使用者對於 的滿意程度。現有的統計工具只能統計某乙個視窗中,使用者的滿意程度的均值。夾克老爺想讓你為統計工具新增乙個新feature,即在統計均值的同時,計算視窗中滿意程度的標準差和中位數 均值需...