Gym - 101845K 排序+概率
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.
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
2
2 0.5
3 1.0
2.500000000
2
0 0.4
20 0.6
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\n",1.0*ans/(double)n); }
Gym - 101845K 排序+概率的更多相关文章
- 【BZOJ3036】绿豆蛙的归宿 拓补排序+概率
[BZOJ3036]绿豆蛙的归宿 Description 随着新版百度空间的下线,Blog宠物绿豆蛙完成了它的使命,去寻找它新的归宿. 给出一个有向无环的连通图,起点为1终点为N,每条边都有一个长度. ...
- 「10.28」Dove 打扑克(链表)·Cicada 与排序(概率)·Cicada 拿衣服(各种数据结构)
A. Dove 打扑克 考场思考半天线段树树状数组,没有什么想法 打完暴力后突然想到此题用链表实现会很快. 因为只有$n$堆,所以设最多有$x$个不同的堆数,那么$x\times (x-1)/2==n ...
- A - Arcade Game Gym - 100814A (概率思维题)
题目链接:https://cn.vjudge.net/contest/285964#problem/A 题目大意:每一次给你你一个数,然后对于每一次操作,可以将当前的数的每一位互换,如果互换后的数小于 ...
- Codeforces Round #253 (Div. 1) (A, B, C)
Codeforces Round #253 (Div. 1) 题目链接 A:给定一些牌,然后如今要提示一些牌的信息,要求提示最少,使得全部牌能够被分辨出来. 思路:一共2^10种情况,直接暴力枚举,然 ...
- Learning To Rank之LambdaMART前世今生
1. 前言 我们知道排序在非常多应用场景中属于一个非常核心的模块.最直接的应用就是搜索引擎.当用户提交一个query.搜索引擎会召回非常多文档,然后依据文档与query以及用户的相关程度对 ...
- [笔记]Learning to Rank算法介绍:RankNet,LambdaRank,LambdaMart
之前的博客:http://www.cnblogs.com/bentuwuying/p/6681943.html中简单介绍了Learning to Rank的基本原理,也讲到了Learning to R ...
- CVPR2018: Unsupervised Cross-dataset Person Re-identification by Transfer Learning of Spatio-temporal Patterns
论文可以在arxiv下载,老板一作,本人二作,也是我们实验室第一篇CCF A类论文,这个方法我们称为TFusion. 代码:https://github.com/ahangchen/TFusion 解 ...
- Learning to Rank算法介绍:RankNet,LambdaRank,LambdaMart
之前的博客:http://www.cnblogs.com/bentuwuying/p/6681943.html中简单介绍了Learning to Rank的基本原理,也讲到了Learning to R ...
- 2016"百度之星" - 初赛(Astar Round2A)Gym Class(拓扑排序)
Gym Class Accepts: 849 Submissions: 4247 Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65 ...
随机推荐
- spring bean管理
轻量级,无侵入 Bean管理 1 创建applicationContext.xml 2 配置被管理的Bean 3 获取Bean pom.xml配置 <dependency> <gro ...
- C#理解泛型(源代码)及 default(T)
1.类型不安全.且代码无法遍历重用的源代码. 2.泛型源代码 源代码下载: http://files.cnblogs.com/files/qqhfeng/ConsoleApplication1.rar
- 【275】◀▶ Python 控制语句说明
参考:Python循环语句 01 for 循环语句. 02 while 循环语句. 03 if...else 选择语句. 04 continue 执行循环语句中的下一条循环. 05 ...
- OpenCV4Android 不需要安装OpenCVManager,就可以运行的方法
http://blog.csdn.net/yanzi1225627/article/details/27863615 OpenCV4Android释疑: 透析Android以JNI调OpenCV的三种 ...
- python笔记--3--函数、生成器、装饰器、函数嵌套定义、函数柯里化
函数 函数定义语法: def 函数名([参数列表]): '''注释''' 函数体 函数形参不需要声明其类型,也不需要指定函数返回值类型 即使该函数不需要接收任何参数,也必须保留一对空的圆括号 括号后面 ...
- day70-oracle 12-Java调用存储过程和存储函数
我们现在调用的是存储过程和存储函数.用CallableSatement调用存储函数和存储过程. RDBMS:关系数据库.使用标准方式调用存储过程.也就是说:在mysql中调用和在oracle中调用的写 ...
- 定时node-schedule 模块的使用
You can install using npm. npm install node-schedule var schedule = require('node-schedule'); var j ...
- yii2常用excel操作库
yii2使用较多的excel操作库 1."phpoffice/phpexcel" https://github.com/PHPOffice/PHPExcel/archive/1.8 ...
- ARC102E Stop. Otherwise...
传送门 题目大意 现在有n个k面的骰子,问在i=2~2*k的情况下,任意两个骰子向上那一面的和不等于i的方案数是多少. 分析 这道题具体做法见这个博客. 至于k2的值为啥是那个自己画画图就明白了. 代 ...
- python---pyspider,报错?
conf.json文件内容如下: { "message_queue": "redis://127.0.0.1:6379/15", "webui&quo ...