Problem F. Judging Time Prediction

题目连接:

http://www.codeforces.com/gym/100253

Description

It is not easy to predict. Do you know that the modern weather prediction is marginally better than to

use the previous day weather as a prediction for the next day?

This problem is about judging a submission on a programming contest like ACM-ICPC. Suppose there is

a single submission for the problem containing n tests. Based on the previous statistics for each test we

know ti the expected time to judge on it and pi the probability of a submission to pass the test.

There are m judging machines in the system. They are completely independent and are used to judge a

submission on multiple tests at the same time. They work as follows. Each time a judging machine has

no task (has just started or nished processing the previous job), it chooses the unprocessed test with the

smallest number and judges submission on the chosen test. If it was judged on the i-th test, then after

time ti the verdict will be known. As it was written above, the probability that a submission passes the

test is pi

.

Let's assume that the judging process starts at the same moment when all the judging machines start. So

at this moment the rst min(m, n) tests start on the judging machines.

You know that on ACM-ICPC contests it is not necessary to judge a submission on all tests. The judging

process will be aborted at the rst moment when two conditions are met at the same time:

• the solution was judged on some test (say, x) and didn't pass it,

• the solution was judged on all the tests 1, 2, . . . , x − 1 and passed all of them.

Naturally, if all the tests are judged and passed the judging process ends too.

Write a program to print the expected time to judge a submission. It means that you are to nd the

mathematical expectation of the judging time according to the specied model.

Input

The rst line of the input contains two integer numbers n and m (1 ≤ n ≤ 3 · 105

, 1 ≤ m ≤ 3 · 105

) the

number of tests and judging machines. The following n lines contain pairs of integers ti and real numbers

pi (1 ≤ ti ≤ 100, 0 < pi < 1), where ti

is the time required to judge the i-th test and pi

is the probability

to pass the i-th test. The values pi are given with no more than 4 digits after the decimal point.

Output

Print the only real number e the expected time to judge the submission. Print it with at least 4 digits

after the decimal point.

Sample Input

2 1

1 0.5

2 0.5

Sample Output

2.0000000000

Hint

题意

有n组test,m个测评姬。

每个空闲的测评姬,会找到当前序号最小,没有测评姬测的测试点进行测试。

其中满足:

1.x测试点wa了

2.前面所有的测试点都测完了。

这个测试就会结束。

现在告诉你每个测评点需要的时间,以及通过的概率,问你期望测试时间。

题解:

拿一个优先队列,测出究竟是哪个测评姬测试这个测试点,以及这个测试点结束的时间。

那么对于第i个测评点的贡献,就是前缀最大值乘上这个测试点挂掉的概率。

代码

#include <bits/stdc++.h>
#define rep(a,b,c) for(int (a)=(b);(a)<=(c);++(a))
#define drep(a,b,c) for(int (a)=(b);(a)>=(c);--(a))
#define pb push_back
#define mp make_pair
#define sf scanf
#define pf printf
#define two(x) (1<<(x))
#define clr(x,y) memset((x),(y),sizeof((x)))
#define dbg(x) cout << #x << "=" << x << endl;
const int mod = 1e9 + 7;
int mul(int x,int y){return 1LL*x*y%mod;}
int qpow(int x , int y){int res=1;while(y){if(y&1) res=mul(res,x) ; y>>=1 ; x=mul(x,x);} return res;}
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
using namespace std;
const int maxn = 3e5 + 500;
int N , K , t[maxn] ;
long long CompleteTime[maxn];
double prefixp[maxn];
double p[maxn];
double prob = 1.;
struct data{
long long x ;
int index;
friend bool operator < ( const data & a , const data & b ){ return a.x > b.x; }
data( long long x , int index ) : x(x) , index( index ) {}
}; priority_queue < data > Q; int main(int argc,char *argv[]){
//freopen("in.txt" , "r" , stdin );
N = read() , K = read();
prefixp[0] = 1;
for(int i = 1 ; i <= N ; ++ i){
scanf("%d%lf" , t + i , p + i );
prefixp[i] = prefixp[ i - 1 ] * p[i];
}
for(int i = 1 ; i <= min( N , K ) ; ++ i){
Q.push( data( t[i] , i ) );
}
int ptr = min( N , K ) ;
double ans = 0;
while( !Q.empty() ){
data st = Q.top() ; Q.pop();
CompleteTime[st.index] = st.x;
++ ptr;
if( ptr <= N ) Q.push( data( st.x + t[ptr] , ptr ));
}
long long s = 0;
for(int i = 1 ; i <= N ; ++ i){
s = max( s , CompleteTime[i] );
ans += s * prefixp[i - 1] * ( 1. - p[i] ) ;
}
ans += s * prefixp[N];
pf("%.10lf\n" , ans);
return 0;
}

2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem F. Judging Time Prediction 优先队列的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  4. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  5. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

  6. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...

  7. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  8. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution

    A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...

  9. 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing

    [链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...

随机推荐

  1. 转 -----那些年总也记不牢的IO

    关于资源关闭: 一般情况下是:先打开的后关闭,后打开的先关闭 另一种情况:看依赖关系,如果流a依赖流b,应该先关闭流a,再关闭流b 例如处理流a依赖节点流b,应该先关闭处理流a,再关闭节点流b 当然完 ...

  2. ASP.NET MVC学习笔记-----Filter(1)

    Filter类型 接口 MVC的默认实现 Description Authorization IAuthorizationFilter AuthorizeAttribute 最先执行,在其他类型的fi ...

  3. html template--(来自网易)

    html template   概述 包含完整头部信息和主体结构的HTML基础模板. 代码展示 <!DOCTYPE html> <html> <head> < ...

  4. ASP.NET实现网站的自动升级

    网站的自动升级主要是要实现从一台服务器上下载某些文件到本服务器上,然后对下载下来的文件进行更新等操作. 比如,现在有服务器A,服务器B和客户端C. 作为COM公司开发的产品DIV网站系统被安装到服务器 ...

  5. iOS 自己封装的网络请求,json解析的类

    基本上所有的APP都会涉及网络这块,不管是用AFNetWorking还是自己写的http请求,整个网络框架的搭建很重要. 楼主封装的网络请求类,包括自己写的http请求和AFNetWorking的请求 ...

  6. 【干货】使用EnCase来分析windows 7文件系统------认识元数据记录$MFT,数据恢复

    来源:Unit 6: Windows File Systems and Registry 6.1 Windows File Systems and Registry Windows NTFS File ...

  7. C语言内存分布

    C语言内存分布 典型的C语言程序内存表示分区共有5个部分: 正文段 Text segment 已初始化数据段(数据段)Initialized data segment 未初始化数据段(bss)Unin ...

  8. 升级openssh到最新版本

    首先,下载最新版本,传到服务器:http://mirror.aarnet.edu.au/pub/OpenBSD/OpenSSH/portable/ 安装 cd /root/ mkdir ssh_upg ...

  9. TCP/UDP区别&&心跳包机制【转】

    转自:https://www.jianshu.com/p/6d93a3c21c34 UDP:用户数据报协议:主要用在实时性要求比较高的以及对质量相对较弱的地方.但是面对现在高质量的线路不会容易丢包,除 ...

  10. linux远程windows执行命令

    Linux下远程连接windows,执行命令 - Feng______的专栏 - 博客频道 - CSDN.NEThttp://blog.csdn.net/feng______/article/deta ...