题目链接:http://codeforces.com/problemset/problem/284/C

题目意思:给出3种操作:t = 1:在前 a 个数中每个数都加上x; t= 2:在数组末尾增加一个数k,数组长度相应增加1; t = 3:删除数组最后一个数,数组长度减少1。对于n次操作,都给出整个数组所有元素的平均值。

一开始看见题目意思那么容易懂,于是以为很容易做,错足14次,15次终于成功了。先是TLE(对操作2直接暴力循环加),后在Test 10 wa wa wa~~~,说误差超了,全部不知道是什么回事!

其实3个操作不需要都模拟出来,操作3是比较麻烦的,因为删除的数有可能经过 t = 1有所变化。所以很自然地想到要追踪当前要删除的数经过t = 1 时的改变,这样就需要开多一个数组来记录这些位置。

代码中标上“关键”那里是很重要的,代表要清除操作1对数组中最后一个数的处理,否则新的一轮操作1会累加这种操作,这样结果就不正确了。

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = *1e5 + ;
int a[maxn], mark[maxn]; int main()
{
int n, i, t, x, l, len;
while (scanf("%d", &n) != EOF)
{
memset(mark, , sizeof(mark));
a[len=] = ;
double sum = ;
while (n--)
{
scanf("%d", &t);
if (t == )
{
scanf("%d%d", &l, &x);
sum += (double) l * x;
mark[l] += x;
}
else if (t == )
{
scanf("%d", &x);
sum += x;
a[++len] = x;
}
else
{
if (len >= )
{
sum -= a[len]; //减最后一个数
sum -= mark[len]; //减最后一个数经过操作1时可能的变化
mark[len-] += mark[len];
mark[len] = ; // 这个是关键啊
len--;
}
}
printf("%.7lf\n", (double)sum/len);
}
}
return ;
}

ps:学完树状数组后会补上运用树状数组解决的方法

codeforces C. Cows and Sequence 解题报告的更多相关文章

  1. Codeforces Educational Round 92 赛后解题报告(A-G)

    Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...

  2. codeforces 476C.Dreamoon and Sums 解题报告

    题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...

  3. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  4. USACO Section2.1 Sorting a Three-Valued Sequence 解题报告

    sort3解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...

  5. CodeForces - 284C - Cows and Sequence

    先上题目: C. Cows and Sequence time limit per test 3 seconds memory limit per test 256 megabytes input s ...

  6. codeforces C. Vasily the Bear and Sequence 解题报告

    题目链接:http://codeforces.com/problemset/problem/336/C 题目意思:给出一个递增的正整数序列 a1, a2, ..., an,要求从中选出一堆数b1, b ...

  7. timus 1175. Strange Sequence 解题报告

    1.题目描述: 1175. Strange Sequence Time limit: 1.0 secondMemory limit: 2 MB You have been asked to disco ...

  8. codeforces 507B. Amr and Pins 解题报告

    题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...

  9. codeforces 500B.New Year Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...

随机推荐

  1. 配置laravel的nginx站点

    server{}配置 server{ #端口配置 listen 80; #域名配置 server_name laravel.cc; index index.php index.html index.h ...

  2. 【UI】为项目添加类似于淘宝筛选列表勾选的ui-choose

    jQuery下载的地址:http://www.htmleaf.com/jQuery/Form/201512182916.html GitHub地址:https://github.com/wangxin ...

  3. [转]Go的50坑:新Golang开发者要注意的陷阱、技巧和常见错误-高级

    from : https://levy.at/blog/11 进阶篇 关闭HTTP的响应 level: intermediate 当你使用标准http库发起请求时,你得到一个http的响应变量.如果你 ...

  4. mt-checklist 的 bug 解疑 及 防止 this 指针偏移

    1.今天在使用 mt-checklist 时,发现 绑定 change 方法后,第一次点击返回的值为 空数组 <template> <div id="app"&g ...

  5. MQTT 测试工具介绍

    eclipse paho 下载地址为: https://repo.eclipse.org/content/repositories/paho-releases/org/eclipse/paho/org ...

  6. Spring学习【Spring概述】

    从本文開始,我们就要一起学习Spring框架,首先不得不说Spring框架是一个优秀的开源框架. 当中採用IoC原理实现的基于Java Beans的配置管理和AOP的思想都是非常值得学习与使用的.以下 ...

  7. 【CODEFORCES】 B. Dreamoon and Sets

    B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. PHP开发环境简析

    单工作机情况 windows + wamp windows + XShell类终端工具 + linux虚拟机 Ubuntu桌面版 自带终端 Mac OS + mamp Mac OS 自带终端 Mac ...

  9. Django+uwsgi+nginx+angular.js项目部署

    这次部署的前后端分离的项目: 前端采用angular.js,后端采用Django(restframework),他俩之间主要以json数据作为交互 Django+uwsgi的配置可以参考我之前的博客: ...

  10. iOS开发:Toast for iPhone

    iOS开发:Toast for iPhone   分享一个我写的类似于android的toast的提示框 主要特点: 1,支持屏幕Y轴任意位置显示,设置距离顶/底端距离 2,支持多行文本 3,支持设置 ...