AIM Tech Round (Div. 1) D. Birthday 数学 暴力
D. Birthday
题目连接:
http://www.codeforces.com/contest/623/problem/D
Description
A MIPT student named Misha has a birthday today, and he decided to celebrate it in his country house in suburban Moscow. n friends came by, and after a typical party they decided to play blind man's buff.
The birthday boy gets blindfolded and the other players scatter around the house. The game is played in several rounds. In each round, Misha catches exactly one of his friends and has to guess who it is. The probability of catching the i-th friend does not change between rounds and is equal to pi percent (as we know, it is directly proportional to the amount of alcohol consumed by the i-th friend) and p1 + p2 + ... + pn = 100 holds. Misha has no information about who he caught. After Misha makes an attempt to guess the caught person, the round ends. Even then, Misha isn't told whether he guessed correctly, and a new round begins.
The game ends when Misha guesses every friend at least once, that is, there exists such set of rounds k1, k2, ..., kn, that during round number ki Misha caught the i-th friend and guessed him. Misha wants to minimize the expectation of the number of rounds of the game. Despite the fact that at any point in the game Misha has no information about who he has already guessed, his friends are honest, and if they see that the condition for the end of the game is fulfilled, the game ends immediately. Find the expectation of the number of rounds in the game if Misha plays optimally.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of Misha's friends.
The second line contains n integers pi (), giving the probability to catch the i-th friend in one particular round in percent.
Output
Print a single real value — the expectation of the number of rounds provided that Misha plays optimally. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .
Sample Input
2
50 50
Sample Output
5.0000000000
Hint
题意
有n个人,你每次有pi的概率猜到第i个人,然后问你期望最少多少次可以把所有人至少都猜到一次
题解:
数学题
i回合以内结束的概率是多少呢?
公式:
P2i = (1-P[i]),表示选不中这个人的概率
显然(1-P2i^k)表示k回合内至少选中一次这个人的概率
所以我们就贪心的选择+1次之后概率最大的那个人去猜就好了
然后再扫一遍统计答案就好了
直接暴力300000次,玄学暴力,当然这个是可以证明误差是正确的
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 120;
priority_queue<pair<double,int> >Q;
double p[maxn];
double p2[maxn];
int cnt[maxn];
double ans[300000];
int n;
double quickpow(double m,long long n)//返回m^n
{
double b = 1.0;
while (n > 0)
{
if (n & 1)
b = (b*m);
n = n >> 1 ;
m = (m*m);
}
return b;
}
double deal(int x)
{
return (1-quickpow(p2[x],cnt[x]+1))/(1-quickpow(p2[x],cnt[x]));
}
double Count(int x)
{
return (1-quickpow(p2[x],cnt[x]));
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lf",&p[i]);
p[i]/=100;
p2[i]=1-p[i];
}
for(int step=1;step<300000;step++)
{
double Max = deal(1);
int tmp = 1;
for(int i=1;i<=n;i++)
{
if(cnt[i]==0)
{
tmp = i;
break;
}
if(deal(i)>Max)
Max=deal(i),tmp=i;
}
cnt[tmp]++;
double pro = 1;
for(int i=1;i<=n;i++)
pro=pro*Count(i);
ans[step]=pro;
}
double ans2 = 0;
for(int i=1;i<300000;i++)
ans2+=1.0*i*(ans[i]-ans[i-1]);
printf("%.12f\n",ans2);
}