Codeforces Round #174 (Div. 2)---C. Cows and Sequence(操作序列)
来源:互联网 发布:淘宝客导购名称怎么填 编辑:程序博客网 时间:2024/05/16 18:46
Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform n operations. Each operation is one of the following:
Add the integer xi to the first ai elements of the sequence.Append an integer ki to the end of the sequence. (And hence the size of the sequence increases by 1)Remove the last element of the sequence. So, the size of the sequence decreases by one. Note, that this operation can only be done if there are at least two elements in the sequence.
After each operation, the cows would like to know the average of all the numbers in the sequence. Help them!
Input
The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of operations. The next n lines describe the operations. Each line will start with an integer ti (1 ≤ ti ≤ 3), denoting the type of the operation (see above). If ti = 1, it will be followed by two integers ai, xi (|xi| ≤ 103; 1 ≤ ai). If ti = 2, it will be followed by a single integer ki (|ki| ≤ 103). If ti = 3, it will not be followed by anything.
It is guaranteed that all operations are correct (don’t touch nonexistent elements) and that there will always be at least one element in the sequence.
Output
Output n lines each containing the average of the numbers in the sequence after the corresponding operation.
The answer will be considered correct if its absolute or relative error doesn’t exceed 10 - 6.
Sample test(s)
Input
5
2 1
3
2 3
2 1
3
Output
0.500000
0.000000
1.500000
1.333333
1.500000
Input
6
2 1
1 2 20
2 2
1 2 -3
3
3
Output
0.500000
20.500000
14.333333
12.333333
17.500000
17.000000
Note
In the second sample, the sequence becomes
用st数组来保存这些数,size表示有多少个数,add数组表示st数组每一个数字应该增加的值
然后实时记录和
/************************************************************************* > File Name: CF-174-C.cpp > Author: ALex > Mail: zchao1995@gmail.com > Created Time: 2015年04月09日 星期四 22时07分59秒 ************************************************************************/#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <queue>#include <stack>#include <map>#include <bitset>#include <set>#include <vector>using namespace std;const double pi = acos(-1.0);const int inf = 0x3f3f3f3f;const double eps = 1e-15;typedef long long LL;typedef pair <int, int> PLL;static const int N = 200100;int st[N];int add[N];int main(){ int n; while (~scanf("%d", &n)) { int o, a, x; double sum = 0; int size = 1; st[1] = 0; memset(add, 0, sizeof(add)); while (n--) { scanf("%d", &o); if (o == 3 && size >= 2) { sum -= (st[size] + add[size]); add[size - 1] += add[size]; add[size] = 0; --size; } else if (o == 1) { scanf("%d%d", &a, &x); sum += (double)a * x; add[a] += x; } else { scanf("%d", &x); ++size; st[size] = x; sum += x; } printf("%.10f\n", sum / size); } } return 0;}
- Codeforces Round #174 (Div. 2)---C. Cows and Sequence(操作序列)
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence
- Codeforces-Round 174(Cows and Sequence)(树状数组、高校算法)
- Codeforces Round #225 (Div. 2) C. Milking cows
- Codeforces Round #225 (Div. 2)-C. Milking cows
- Codeforces 284C Cows and Sequence【思维】
- Codeforces Round #195 (Div. 2) C. Vasily the Bear and Sequence
- Codeforces Round #195 (Div. 2) C--Vasily the Bear and Sequence(贪心)
- Codeforces Round #182 (Div. 2)---C. Yaroslav and Sequence(不错的题,分析找规律)
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence 构造
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence (构造 贪心)
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence(构造,思路)
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence(构造)
- Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence 构造
- Codeforces Round #384 (Div. 2) B Chloe and the sequence
- 读写锁(chapter 8)
- Android 异步加载图片,使用LruCache和SD卡或手机缓存,效果非常的流畅
- 数据结构随笔—动态存储管理
- 写得比较好的设计模式相关博文汇总
- 关于select标签的积累
- Codeforces Round #174 (Div. 2)---C. Cows and Sequence(操作序列)
- Linux查看文件常用命令学习--cat\more\head\tail
- “菜鸟”程序员和“大神”程序员差距在哪里
- 清缘诀
- C库函数
- 架构
- Myeclipse,eclipse中Mybatis Generator插件的手动安装
- 基于Matlab中FDATool工具箱的滤波器设计及相关文件的生成
- android解析网络json数据(1)