- 1#include 2#include 3#include 4#include 5 using namespace std;
- 6 int n,
- sum,
- p,
- num,
- k,
- now,
- cnt,
- s[105],
- a[1000050];
- 7 int read() 8 {
- 9 int x = 0,
- f = 1;
- char c = getchar();
- 10
- while (c < '0' || c > '9') {
- if (c == ' - ') f = -1;
- c = getchar();
- }
- 11
- while (c >= '0' && c <= '9') {
- x = x * 10 + c - '0';
- c = getchar();
- }
- 12
- return x * f;
- 13
- }
- 14 int main() 15 {
- 16 n = read();
- k = read();
- 17
- while (n--) 18 {
- 19 p = read();
- 20
- if (p == 1) 21 {
- 22 num = read();
- 23 a[++cnt] = num;
- 24
- if (now == k) sum = sum - a[cnt - k] + num,
- s[a[cnt - k]]--;
- 25
- else now++,
- sum += num;
- 26 s[num]++;
- 27
- }
- 28
- else if (p == 2) printf("%.2lf\n", floor((double) sum / now));
- 29
- else if (p == 3) 30 {
- 31 double w = (double) sum / now,
- ans = 0;
- 32
- for (int i = cnt - now + 1; i <= cnt; i++) ans += ((double) a[i] - w) * ((double) a[i] - w);
- 33 printf("%.2lf\n", ans / now);
- 34
- }
- 35
- else 36 {
- 37
- if (now % 2) 38 {
- 39 int pos = now / 2 + 1,
- ans = 0;
- 40
- for (int i = 0; i <= 100; i++) 41 {
- 42 ans += s[i];
- 43
- if (ans >= pos) 44 {
- 45 printf("%.2lf\n", (double) i);
- 46
- break;
- 47
- }
- 48
- }
- 49
- }
- 50
- else 51 {
- 52 int pos1 = now / 2,
- pos2 = now / 2 + 1,
- st = -1,
- ed = -1,
- ans = 0;
- 53
- for (int i = 0; i <= 100; i++) 54 {
- 55 ans += s[i];
- 56
- if (ans >= pos1 && st == -1) st = i;
- 57
- if (ans >= pos2 && ed == -1) ed = i;
- 58
- if (st != -1 && ed != -1) 59 {
- 60 printf("%.2lf\n", (double)(st + ed) / 2);
- 61
- break;
- 62
- }
- 63
- }
- 64
- }
- 65
- }
- 66
- }
- 67
- return 0;
- 68
- }
来源: http://www.bubuko.com/infodetail-2135398.html