2016-2017 ACM-ICPC, NEERC, Moscow Subregional Contest Problem L. Lazy Coordinator

Posted destr

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2016-2017 ACM-ICPC, NEERC, Moscow Subregional Contest Problem L. Lazy Coordinator相关的知识,希望对你有一定的参考价值。

题目来源: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
",ans[i]-t[i]);
    }
    return 0;
}
















以上是关于2016-2017 ACM-ICPC, NEERC, Moscow Subregional Contest Problem L. Lazy Coordinator的主要内容,如果未能解决你的问题,请参考以下文章

2016-2017 ACM-ICPC, NEERC, Moscow Subregional Contest Problem L. Lazy Coordinator

2013-2014 ACM-ICPC, NEERC, Eastern Subregional Contest PART (7/10)

2017-2018 ACM-ICPC, NEERC, Moscow Subregional Contest

模拟赛小结:2014-2015 ACM-ICPC, NEERC, Southern Subregional Contest

GYM1014092010-2011 ACM-ICPC, NEERC, Western Subregional Contest

2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17)