题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229511

时间限制:1s

空间限制:512MB

题目大意:

给定一个n

随后跟着2n行输入

"+ t":表示在t时刻获得了一样东西

"- t":表示在t时刻使用了一样东西

求每件东西等待时间的期望(得到的东西无先后顺序)

数据范围:

1 ≤ n ≤ 100 000

t ≤ 1e9

样例:



题目解法:

使用递推式从后往前推

代码:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pi acos(-1.0)
#define mem0(a) memset(a,0,sizeof(a))
#define memf(b) memset(b,false,sizeof(b))
#define ll long long
#define eps 1e-10
#define inf 1e17
#define maxn 201010
int num[maxn],op[maxn];
db t[maxn],ans[maxn];
int main()
{
int n;
char z;
scanf("%d",&n);
n*=2;
for(int i=1;i<=n;i++)
{
cin>>z>>t[i];
if(z=='-')
op[i]=-1;
else
op[i]=1;
}
for(int i=1;i<=n;i++)
{
num[i]=num[i-1]+op[i];
}
for(int i=n;i>=1;i--)
{
if(op[i]==-1)
{
db p=(db)(1)/num[i-1];
ans[i]=p*t[i]+(1-p)*ans[i+1];
}
else
ans[i]=ans[i+1];
}
// for(int i=1;i<=n;i++)
// cout<<ans[i]<<" ";
rep(i,1,n+1)
{
if(op[i]==1)
printf("%.12Lf\n",ans[i]-t[i]);
}
return 0;
}

2016-2017 ACM-ICPC, NEERC, Moscow Subregional Contest Problem L. Lazy Coordinator的更多相关文章

  1. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem D. Distance 迪杰斯特拉

    Problem D. Distance 题目连接: http://codeforces.com/gym/100714 Description In a large city a cellular ne ...

  2. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem C. Contest 水题

    Problem C. Contest 题目连接: http://codeforces.com/gym/100714 Description The second round of the annual ...

  3. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem K. KMC Attacks 交互题 暴力

    Problem K. KMC Attacks 题目连接: http://codeforces.com/gym/100714 Description Warrant VI is a remote pla ...

  4. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem J. Joke 水题

    Problem J. Joke 题目连接: http://codeforces.com/gym/100714 Description The problem is to cut the largest ...

  5. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem I. Interest Targeting 模拟题

    Problem I. Interest Targeting 题目连接: http://codeforces.com/gym/100714 Description A unique display ad ...

  6. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem H. Hometask 水题

    Problem H. Hometask 题目连接: http://codeforces.com/gym/100714 Description Kolya is still trying to pass ...

  7. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem F. Finance 模拟题

    Problem F. Finance 题目连接: http://codeforces.com/gym/100714 Description The Big Boss Company (BBC) pri ...

  8. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem A. Alien Visit 计算几何

    Problem A. Alien Visit 题目连接: http://codeforces.com/gym/100714 Description Witness: "First, I sa ...

  9. 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem L. Stock Trading Robot 水题

    Problem L. Stock Trading Robot 题目连接: http://www.codeforces.com/gym/100253 Description CyberTrader is ...

随机推荐

  1. 如何用GDI+画个验证码

    如何使用GDI+来制作一个随机的验证码 绘制验证码之前先要引用 using System.Drawing; using System.Drawing.Drawing2D; 首先,先写一个方法来取得验证 ...

  2. JS参考手册

    一.JavaScript Core API 词法结构 字符集 使用Unicode字符集 注释 单行注释 //或HTML风格的<!-- 多行注释 /**/ 标识符 大小写 区分大小写 空格.换行. ...

  3. Kafka消息系统

    一.基本概念 Kafka是一个分布式的.可分区的.可复制的消息系统.它提供了普通消息系统的功能,但具有自己独特的设计. 首先让我们看几个基本的消息系统术语: Kafka将消息以topic为单位进行归纳 ...

  4. Anaconda快速加载opencv

    刚刚发现了两种Anaconda快速加载opencv的方法,亲测有效: 第一种: 直接在Navigator Environment 中搜opencv 如果搜不到,登陆Anaconda Cloud官网 h ...

  5. 20155317 2016-2017-2《Java程序设计》课程总结

    20155317 2016-2017-2<Java程序设计>课程总结 每周作业链接汇总 新玮的首发博客:对师生关系的期望. C语言与java 20155317 王新玮第二次:语言掌握调查 ...

  6. day1 创建X00001文件1K

    要求:创建文件名为:X000001-X999999,大小为1K 的文件 版本1) import os #1.输入要创建的文件数量 nums = int(input("nums:") ...

  7. 【LG3235】 [HNOI2014]江南乐

    题目描述 给出\(n\)堆石子, 每次可以选择将大于某个数\(f\)一堆平均分成多个堆, 最后不能操作的失败. 题解 10pts 直接爆搜即可. 70pts 像我们对这类题目的常规操作那样,将一整个局 ...

  8. 图论-求有向图的强连通分量(Kosaraju算法)

    求有向图的强连通分量     Kosaraju算法可以求出有向图中的强连通分量个数,并且对分属于不同强连通分量的点进行标记. (1) 第一次对图G进行DFS遍历,并在遍历过程中,记录每一个点的退出顺序 ...

  9. Awesome TensorFlow

    Awesome TensorFlow  A curated list of awesome TensorFlow experiments, libraries, and projects. Inspi ...

  10. JS基础,课堂作业,相亲问答

    相亲问答 <script> var a = prompt("你有房子么?"); var b = prompt("你有钱么?"); var c = p ...