hdu 5035 Delivery 概率题 2014 ACM/ICPC Asia Regional Beijing Online

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5035

Problem Description
Today, Matt goes to delivery a package to Ted. When he arrives at the post office, he finds there are N clerks numbered from 1 to N. All the clerks are busy but there is no one else waiting in line. Matt will go to the first clerk who has finished the service for the current customer. The service time t i for clerk i is a random variable satisfying distribution p(t i = t) = k ie^(-k it) where e represents the base of natural logarithm and k i represents the efficiency of clerk i. Besides, accroding to the bulletin board, Matt can know the time c i which clerk i has already spent on the current customer. Matt wants to know the expected time he needs to wait until finishing his posting given current circumstances.
 

Input
The first line of the input contains an integer T,denoting the number of testcases. Then T test cases follow.

For each test case, the first line contains one integer:N(1<=N<=1000)

The second line contains N real numbers. The i-th real number k i(0<=k i<=1) indicates the efficiency of clerk i.

The third line contains N integers. The i-th integer indicates the time c i(0<=c i<=1000) which clerk i has already spent on the current customer.
 

Output
For each test case, output one line "Case #x: y", where x is the case number (starting from 1), y is the answer which should be rounded to 6 decimal places.
 

Sample Input
  
  
2 2 0.5 0.4 2 3 3 0.1 0.1 0.1 3 2 5
 

Sample Output
  
  
Case #1: 3.333333 Case #2: 13.333333
 

Source


后悔没学概率论,要补课了...

参考别人的讲解:https://www.zybuluo.com/rihkddd/note/34286

题目大意:

Matt一个发快递,快递点有N个职员,职员处理一个客户的时间服从指数分布: f(t)=λeλt ,其中的参数 λ 为职员的效率,现在给出每个职员的效率,同时给了一个场景:现在每个职员都有且只有客户在服务中,此人还从信息牌得知了每个职员已经为当前客户服务了c时间,题目中也给出了,一旦有客户被服务完毕,则这个人就立刻去接受服务。问在此场景下,这个人发快递需要的时间的期望是多少?

解析:

首先指数分布的一些性质:
一个指数分布的概率密度函数是:

f(xλ)={λeλx0,x0,,x<0.

概率分布函数为:
F(xλ)={1eλx0,x0,,x<0.

指数分布具有“无记忆性”,如果一个随机变量呈指数分布,它的条件概率遵循:
P(T>s+t|T>t)=P(T>s)for all s,t0.

然后分析该题目,利用指数分布的无记忆性可以知道,如 t0 时刻,第 i 个职员第一个服务完当前客户,那么接着就会服务Matt,然后服务完Matt。这个过程时间的期望就是我们要求的结果。
因此我们要求的就是:
i=1N+0(E(Xi)+x)λieλiji(+xf(x:λj)dx)dx

解释下上面长长的式子:
i 个职员t时刻接待Matt的概率为 λieλi (此时第i个结束时间为t的概率),乘上 ji+xf(x:λj)dx (其它职员结束时间大于t的概率));而这种情况下的时间为 (E(Xi)+t)
t可以从 0 一直取到 + ,把所有的职员按照上面的情况分析一边,就有了上面的那个式子了。由于指数分布的无记忆性,可以知道题目中给的已服务时间实际上是没有用的……
剩下的就是一些化简计算了,
k=1N+0(E(Xi)+x)λieλiji(+xf(x:λj)dx)dx=k=1N+0(E(Xi)+x)λieλijieλjdx=k=1N+0(E(Xi)+x)λieNi=1λidx=k=1N(1Ni=1λi+λi(Ni=1λi)2)=N+1Ni=1λi


看懂公式后,代码就很简单了...

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>

using namespace std;

#define min2(x, y)     min(x, y)
#define max2(x, y)     max(x, y)
#define min3(x, y, z)  min(x, min(y, z))
#define max3(x, y, z)  max3(x, max(y, z))
#define clr(x, y)      memset(x, y, sizeof(x))
#define fr(i,n)        for(int i = 0; i < n; i++)
#define fr1(i,n)       for(int i = 1; i < n; i++)
#define upfr(i,j,n)    for(int i = j; i <= n; i++)
#define dowfr(i,j,n)   for(int i = n; i >= j; i--)
#define scf(n)         scanf("%d", &n)
#define scf2(n,m)      scanf("%d %d",&n,&m)
#define scf3(n,m,p)    scanf("%d %d %d",&n,&m,&p)
#define ptf(n)         printf("%d",n)
#define ptf64(n)       printf("%I64d",n)
#define ptfs(s)        printf("%s",s)
#define ptln()         printf("\n")
#define ptk()          printf(" ")
#define ptc(c)         printf("%c",c)
#define srt(a,n)       sort(a,n)
#define LL long long
#define pi acos(-1.0)
#define inf 1 << 31-1
#define eps 0.00001
#define maxn 10005
#define mod 10000007

int main()
{
	//freopen("in.txt", "r", stdin);
	int t;
	scf(t);
	int ca = 1;
	while(t--)
	{
		int n;
		scf(n);
		double sum = 0;
		fr(i, n)
		{
			double k;
			scanf("%lf", &k);
			sum += k;
		}
		fr(i, n)
		{
			int c;
			scf(c);
		}
		printf("Case #%d: %.6lf\n", ca++, (n+1) / sum);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值