• Gym


    The UNAL programming coaches have lost a bet, they bet the 6 UNAL teams would occupy the first six positions in the regional finals. Now, they have to shave their heads!. Some of them have more hair than others, and consequently, it takes more time to shave a head completely. However, all of the coaches really love their hair, therefore there is a probability that some (posibly all) of them daunt at the very last moment and do not permit the hairdresser to shave their heads.

    Norbert, the hairdresser who loves probability, would like to order the coaches' schedule such that the average time in the hair salon is minimized for all the coaches. First all the coaches are there at the same time, then they start going one by one to Norbert, if by the moment a coach has to go to the hairdresser, he or she daunts then he or she simply leaves the hair salon and it is the turn of the next coach, after the head of a coach is shaved then that coach leaves the hair salon. The time between turns is negligible.

    For example, suppose that shaving Diego's head takes 2 minutes and shaving Ivan's takes 3 minutes, but Diego has probability of 0.5 of not daunting meanwhile Ivan for sure will shave his head. If Ivan goes first, he will stay 3 minutes in the hair salon and Diego will stay there 3 minutes if daunting or 5 minutes if not (3 of them waiting for Ivan to finish), in this case the average expected time of the coaches in the hair salon would be 3.5, note this is not the optimal arrangement.

    Now, Norbert knows the time it takes to shave each head and the probability of a coach to accept to have the head shaved in the barbershop, help him to know the minimum average expected time in the hair salon of the coaches.


    Input

    The first line of input is an integer n (1 ≤ n ≤ 5 * 105) - the number of coaches.

    The next n lines contain each an integer x (0 ≤ x ≤ 100) and a decimal number y (0 ≤ y ≤ 1) separated by a single space - the time in minutes it takes to shave the head of the i - th coach and his probability of not daunting, respectively.

    Output

    Print the minimum expected average time. The relative error of your answer should not exceed 10 - 6.

    Examples
    Input
    2
    2 0.5
    3 1.0
    Output
    2.500000000
    Input
    2
    0 0.4
    20 0.6
    Output
    6.000000000
    从小到大排序,然后累计即可;
    #include<bits/stdc++.h>
    using namespace std;
    #define maxn 600005
    #define inf 999999999999
    //#define INF 1e18
    #define rdint(x) scanf("%d",&x)
    #define rdllt(x) scanf("%lld",&x)
    #define rdult(x) scanf("%lu",&x)
    #define rdlf(x) scanf("%lf",&x)
    #define rdstr(x) scanf("%s",x)
    typedef long long  ll;
    const long long int mod=1e9+7;
    #define ms(x) memset((x),0,sizeof(x))
    
    int n;
    struct node{
    	int x;
    	double prop;
    }t[maxn];
    double ans=0.0;
    double tmp[maxn];
    
    main(){
     //   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
        cin>>n;
        for(int i=1;i<=n;i++)rdint(t[i].x),rdlf(t[i].prop),tmp[i]=1.0*t[i].x*t[i].prop;
        sort(tmp+1,tmp+1+n);
        for(int i=1;i<=n;i++){
        	ans+=tmp[i]*1.0*(n-i+1);
    	}
    	printf("%.7lf
    ",1.0*ans/(double)n);
    	
    }
    
    
    
    EPFL - Fighting
  • 相关阅读:
    dll相对路径设置
    OPC UA Error: Could not add self-signed certificate to certficate store.
    PB调用C#封装的视频插件中拍照方法不生效的问题
    net反射加载出现错误: ex = {“无法加载一个或多个请求的类型。有关更多信息,请检索 LoaderExceptions 属性。”}
    xtralayout模式下,修改 layOutcontrolgroup分组框表头背景颜色步骤
    abap 本地包 生成请求号
    PB调用SAP的Web Service结构体数组参数方法详解(使用C#调用Web Service生成dll)
    zookeeper NIOServerCnxn: Too many connections from IP- max i
    mysql 10038错误解决方案
    PHP获取文件夹内所有文件包括子目录文件的名称或路径
  • 原文地址:https://www.cnblogs.com/zxyqzy/p/10300798.html
Copyright © 2020-2023  润新知