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