博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Gym - 101845K 排序+概率
阅读量:6919 次
发布时间:2019-06-27

本文共 3036 字,大约阅读时间需要 10 分钟。

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
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\n",1.0*ans/(double)n); }

 

 

转载于:https://www.cnblogs.com/zxyqzy/p/10300798.html

你可能感兴趣的文章
微软宣布Azure Functions正式支持Java
查看>>
企业IT部门主管告诉你,DevOps给我们带来了这些变化
查看>>
2018年最受欢迎的Python库,你都用过吗?
查看>>
Java 8 vs. Scala之Lambda表达式
查看>>
用Git虚拟文件系统来解决大型存储问题
查看>>
敲山震虎?继MongoDB之后,AWS又对Elasticsearch下手了
查看>>
如何成为一家敏捷银行
查看>>
Python数据科学平台Anaconda的最新发布中增加了Microsoft VS Code
查看>>
React Native 实践之携程 Moles 框架
查看>>
Elixir: Syn,一个分布式进程注册表和进程组管理器
查看>>
自己整理的DevOps实用资源(授人以鱼不如授人以渔)
查看>>
React Native 的开发工具:Nuclide
查看>>
oracle下sql创建指定年份全年日期表(区分工作日)
查看>>
设计模式(1)
查看>>
过来人经验:程序员怎么升职加薪,迎娶白富美 ...
查看>>
Java基础面试知识点总结
查看>>
Flutter 29: 易忽略的【小而巧】的技术点汇总 (五) ...
查看>>
生物制药CDMO开年最大单笔融资!澳斯康生物制药获超3亿元A轮融资 ...
查看>>
大型数据中心的存储能耗问题与NVM在数据中心中的应用 ...
查看>>
asp.net core系列 32 EF查询数据 必备知识(1)
查看>>