2016-2017 Acm-icpc, NEERC, Moscow subregional Contest problem L. Lazy Coordinator

Source: Internet
Author: User



Title Source: http://codeforces.com/group/aUVPeyEnI2/contest/229511
time limit: 1s
Space limit: 512MB
Main topic:
Given an n
Then follow the 2n line input
"+ T": means to get the same thing at t time
"-T": Indicates the use of the same thing at t moment
Expect everything to wait for time (the things you get in order)
Data range:
1≤n≤100 000
T≤1e9
Examples:

Solution of the problem:
Use recursion to push backwards from behind
Code:


#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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.