1111
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[110], b[110];
double sum = 0; //当前数字的总和
int x2[110]; //数字的平方
double sum2 = 0; //平方和
int cur = 0; // 当前最后一个数字的位置
int n, k;
int op, x;
bool full = false;
int main()
{
scanf("%d%d", &n, &k);
while (n--)
{
scanf("%d", &op);
if (op == 1)
{
scanf("%d", &x);
sum = sum - a[cur] + x;
a[cur] = x;
sum2 = sum2 - x2[cur] + x*x;
x2[cur] = x*x; //平方
cur++;
if (cur == k) cur = 0, full = true;
}
else if (op == 2)
{
int t = k; //设窗口是满的
if (!full) t = cur; //如果窗口没满,那就设成当前位置
printf("%lld.00\n", (ll)(sum/t));
}
else if (op == 3)
{
int t = k;
if (!full) t = cur;
printf("%.2lf\n", sum2/t-(sum/t)*(sum/t));
}
else
{
int t = k;
if (!full) t = cur;
for (int i = 0; i < t; i ++ ) b[i] = a[i];
sort(b, b+t);
if (t % 2 != 0)
printf("%.2lf\n", 1.0*a[t/2]);
else
printf("%.2lf\n", 1.0*(a[t/2]+a[t/2-1])/2);
}
}
return 0;
}
共 5 条回复
什么东西?
???
<i title="刷新" aria-hidden="true" class="redo icon"></i>