Codeforces Round #253 (Div. 2) D. Andrey and Problem

OpenSoucre發表於2014-06-20

關於證明可以參考題解http://codeforces.com/blog/entry/12739

就是將概率從大到小排序然後,然後從大到小計算概率

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdio>
using namespace std;

int main(){
    int n; 
    cin >> n;
    vector<double> p(n);
    for(int i = 0 ; i < n ; ++ i) cin>> p[i];
    sort(p.begin(),p.end(), greater<double>());
    double P=0 ,S=1.0, res = 0.0;
    if(1-p[0] < 1e-10) res =  1.0;
    else{
        for(int i = 0 ; i < n; ++ i){
            P +=p[i]/(1-p[i]);
            S *=(1-p[i]);
            res = max(res,P*S);
        }
    }
    printf("%.10f\n",res);
}

 

相關文章