제출 #856534

#제출 시각아이디문제언어결과실행 시간메모리
856534AlphaMale06Balloons (CEOI11_bal)C++14
30 / 100
254 ms6736 KiB
#include <bits/stdc++.h>

using namespace std;

#define double long double
#define mp make_pair
#define F first
#define S second

double dist(double r1, double x1, double r2, double x2){
    return (x1-x2)*(x1-x2)+(r1-r2)*(r1-r2);
}

double bs(double lo, double hi, double xc, double rp, double xp){
    while(abs(lo-hi)>0.00001){
        double s=(lo+hi)/2;
        double dist1=s+rp;
        dist1*=dist1;
        if(dist1<dist(s, xc, rp, xp)){
            lo=s;
        }
        else{
            hi=s;
        }
    }
    return lo;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int r[n];
    int x[n];
    for(int i=0; i< n; i++){
        cin >> x[i] >> r[i];
    }
    double ans[n];
    stack<pair<double, double>> st;
    for(int i=0; i< n; i++){
        if(st.empty()){
            st.push(mp(r[i], x[i]));
            ans[i]=r[i];
        }
        else{
            double lo=0; double hi=r[i];
            while(true){
                if(st.empty())break;
                hi=bs(lo, hi, x[i], st.top().F, st.top().S);
                if(hi>=st.top().F)st.pop();
                else break;
            }
            st.push(mp(hi, x[i]));
            ans[i]=hi;
        }
    }
    cout << fixed << setprecision(4);
    for(int i=0; i< n; i++){
        cout << ans[i] << "\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...