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 ... 
随机推荐
- 关于:cross_validation.scores
			# -*- coding: utf-8 -*- """ Created on Wed Aug 10 08:10:35 2016 @author: Administrato ... 
- Shell编程进阶   2.2 shell数组
			给一个字符指定一个数组 怎么显示数组 a= echo $a a=( ) echo $a echo ${a[@]} echo ${a[*]} 指定显示数组中第几个数字 echo ${a[]} echo ... 
- 【264】◀▶ Windows 批处理(CMD)
			参考:Windows Commands 微软官方帮助 参考:DOS命令自学小窍门:巧用help命令 参考:bat批处理的注释语句 打开文件夹: start D:\abc 打开D盘abc文件夹 打开ex ... 
- js闭包(二)
			一.何谓“闭包”? 所谓“闭包(Closure)”,指的是一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分. 描述的如此学术的官方解释,相信很少人能够 ... 
- jetty分析
			jetty处理过程: 1 new Server() (1)初试化线程池 生成固定大小线程数,新来的线程放入BlockingQueue. (2)初始化ServerConnector 初始化 sche ... 
- (内存地址hashcode与对象内容hashcode)分析== 和 equal()方法
			==.equals()和hashCode()字符串测试 1.hashCode() 是根据 内容 来产生hash值的 2.System.identityHashCode() 是根据 内存地址 来产生ha ... 
- 去除Activity上面的标题边框
			实现方法:1.在代码中实现:在此方法setContentView(R.layout.main)之前加入:requestWindowFeature(Window.FEATURE_NO_TITLE);标题 ... 
- 获取百度搜索结果的真实url以及摘要和时间
			利用requests库和bs4实现,demo如下: #coding:utf- import requests from bs4 import BeautifulSoup import bs4 impo ... 
- Hibernate 简易入门教程
			Hibernate HIbernate主要包含如下几个接口:Session,Query,Criteria以及Transaction.这些接口的实现在幕后是紧密相连的. 在一个HIbernate应用程序 ... 
- Centos彻底完全删除已安装软件的办法
			1.查询是否安装了软件 rpm -qa | grep -i 软件名 rpm -qa | grep php 2.删除已安装的软件包 根据第一步显示的软件包名,一个个删除 sudo rpm -e -- 包 ... 
