codeforces -- 283A
3 seconds
256 megabytes
standard input
standard output
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!
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 integersai, 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 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.
5
2 1
3
2 3
2 1
3
0.500000
0.000000
1.500000
1.333333
1.500000
6
2 1
1 2 20
2 2
1 2 -3
3
3
0.500000
20.500000
14.333333
12.333333
17.500000
17.000000 思路:lazy标记,每次只记录最后那个数的增量,需要是再向前传递。
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
long long int Delta[], a[];
double sum;
int main(int argc, char const *argv[])
{
int n, type, add, pos, j;
while(~scanf("%d", &n))
{
sum = .;
memset(Delta, , sizeof(Delta));
a[] = ;
j = ;
for(int i = ; i < n;i ++)
{
scanf("%d", &type);
if(type == )
{
scanf("%d%d", &pos, &add);
Delta[pos] += add;
sum += add*pos;
}
else if(type == )
{
scanf("%d", &add);
a[++j] = add;
sum += add;
}
else
{
sum -= a[j] + Delta[j];
Delta[j-] += Delta[j];
Delta[j--] = ;
}
printf("%.7lf\n", sum/j);
}
}
return ;
}
codeforces -- 283A的更多相关文章
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- 2015前端各大框架比较(angular,vue,react,ant)
前端流行框架大比拼 angular vue react ant-design angularjs angular是个MVVM的框架.针对的是MVVM这整个事.angular的最主要的场景就是单页应用, ...
- [GDI+] 生成缩略图的类文件SmallImage (转载)
直接看代码吧,大家可以直接复制使用 /// <summary> /// 类说明:SmallImage类, /// 编码日期:2012-08-20 /// 编 码 人: 苏飞 /// 联系方 ...
- Unix时间戳 和 NSDate 的转换
一个时间戳字符串:NSString *timeStampStr = @"1441602721"; 转换成时间 double unixTimeStamp ...
- ie8中parseInt字符型数值转换数值型问题
今天在ie8中测试项目发现一个奇怪的问题,"08" "09" 强转竟然变成了: 后来发现ie8把"08" "09" 默认 ...
- Data Abstraction
What is an object? (Page 238) In C++, an object is just a variable, and the purest definition is &qu ...
- Apache Virtual Include
2.目录支持includes: <Directory /> Options None //不支持includes ...
- 纯手工打造dropdownlist控件
先上图吧,看看效果. JS代码: ; (function ($) { var DropdownList = function (oDataSouce, oControlsContainer, oLis ...
- Javascript 中 call 的两种用法
用法一(常见用法): 表现形式为:一个对象.方法.call(另一个对象),意义是用另一个对象代替当前对象,执行当前对象的方法.先看示例: function Class1(){ this.name = ...
- 学习Swift -- 可选链
可空链式调用 可空链式调用是一种可以请求和调用属性.方法及下标的过程,它的可空性体现于请求或调用的目标当前可能为空(nil).如果可空的目标有值,那么调用就会成功:如果选择的目标为空(nil),那么这 ...
- 如何用OS X的Xcode写C语言程序
声明:以下内容非本人原创,转载于别处.拿出来只是分享给FY们,不喜勿喷!原创地址http://blog.yorkxin.org/posts/2009/03/15/fundamental-c-with- ...