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只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- JDBC、Hibernate、Mybaites处理数据的流程及对DAO的理解
以查询一个用户信息(id,name)为例: JDBC 1. 获取一个connection 2. 生成一个statement 3. 拼接SQL语句 4. 查询对象,获取结果集(假设已经找到我们需要的对象 ...
- ubuntu14.04使用wubi安装出错
使用wubi安装后,进入系统是总是提示/分区加载异常,无法正常进入系统. 参考解决方案来自 http://jingyan.baidu.com/article/0aa22375bbffbe88cc0d6 ...
- window.resizeTo()和window.open()
函数:window.resizeTo(width, height) 作用:改变窗口大小到设定的宽和高 参数:width - 宽度像素,必须设定的参数 height - 高度像素,可 ...
- java中时间差计算
public class Utill { public String TimeString(Date currentTime, Date beginTime){ /*默认为毫秒,除以1000是为了转换 ...
- C#中检查网络是否连通的二种方法
using System; 2 using System.Collections.Generic; 3 using System.Text; 4 //方法一 5 using System.Ru ...
- LINQ 101——分区、Join、聚合
一.Partitioning 分区 Take 例1:取前3个数 static void Linq1() { , , , , , , , , , }; ); Console.WriteLine(&quo ...
- List集合的去除重复性练习
package com.java.b.listdmeo.www; import java.util.ArrayList;import java.util.Iterator; import com.ja ...
- 读书笔记之 - javascript 设计模式 - 装饰者模式
本章讨论的是一种为对象增添特性的技术,它并不使用创建新子类这种手段. 装饰者模式可以透明地把对象包装在具有同样接口的另一对象之中,这样一来,你可以给一些方法添加一些行为,然后将方法调用传递给原始对象. ...
- Photon开发实战(2)——开发框架、第一个Photon程序
Photon基础开发框架 Photon (v4)的基本框架.开发框架主要Photon和游戏逻辑(C#)两个部分,如下图最新的Photon v4支持的4种底层协议,游戏开发逻辑Photon目前主要划分为 ...
- 代码世界中的Lambda
“ λ ”像一个双手插兜儿,独自行走的人,有“失意.无奈.孤独”的感觉.λ 读作Lambda,是物理上的波长符号,放射学的衰变常数,线性代数中的特征值……在程序和代码的世界里,它代表了函数表达式,系统 ...