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);
}
AIM Tech Round (Div. 1) D. Birthday 数学 暴力的更多相关文章
- AIM Tech Round (Div. 2) D. Array GCD dp
D. Array GCD 题目连接: http://codeforces.com/contest/624/problem/D Description You are given array ai of ...
- AIM Tech Round (Div. 2) C. Graph and String 二分图染色
C. Graph and String 题目连接: http://codeforces.com/contest/624/problem/C Description One day student Va ...
- AIM Tech Round (Div. 2) B. Making a String 贪心
B. Making a String 题目连接: http://codeforces.com/contest/624/problem/B Description You are given an al ...
- AIM Tech Round (Div. 2) A. Save Luke 水题
A. Save Luke 题目连接: http://codeforces.com/contest/624/problem/A Description Luke Skywalker got locked ...
- Codeforces AIM Tech Round (Div. 2)
这是我第一次完整地参加codeforces的比赛! 成绩 news standings中第50. 我觉这个成绩不太好.我前半小时就过了前三题,但后面的两题不难,却乱搞了1.5h都没有什么结果,然后在等 ...
- AIM Tech Round (Div. 2) B
B. Making a String time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- AIM Tech Round (Div. 2) A
A. Save Luke time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- AIM Tech Round (Div. 1) C. Electric Charges 二分
C. Electric Charges 题目连接: http://www.codeforces.com/contest/623/problem/C Description Programmer Sas ...
- AIM Tech Round (Div. 2) C. Graph and String
C. Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- HDU 5117 Fluorescent
题目链接:HDU-5117 题意为有n盏灯,m个开关,每个开关控制着\( k_{i} \)灯.X为最后亮着的灯的个数,要求出\( E(X^{3} ) * 2^{M} mod (10^9 + 7) \) ...
- aspxpivotgrid 导出excel时,非绑定咧显示为0的情况
using DevExpress.XtraPrinting; Exporter.ExportXlsToResponse(this.Title,TextExportMode.Text,true); // ...
- C++中delete和delete[]的区别(转)
原文链接:http://www.cnblogs.com/charley_yang/archive/2010/12/08/1899982.html 一直对C++中的delete和delete[]的区别不 ...
- Webstorm和Eclipse常用快捷键
快捷键配置 点击“File”-> “settings” Webstorm预置了其他编辑器的快捷键配置,可以点击 默认配置-Eclipse的常用快捷键对照表 查找/代替 Webstorm快捷键 E ...
- 一个gulp用于开发与生产的示例
gulp是一款流行的前端构建工具,可以帮我们完成许多工作:监听文件修改.刷新浏览器.编译Less/Scss.压缩代码.添加md5.合并文件等.gulp的配置和使用特别简单,学习gulp过程中顺便写了一 ...
- mysql性能分析-------profiling和explain
1. profiling之性能分析 MySQL5.0.37版本以上支持了Profiling – 官方手册.此工具可用来查询 SQL 会执行多少时间,System lock和Table lock 花多少 ...
- django开发项目实例2--如何链接图片和css文件(静态文件)
在上一篇随笔里面,我们已经介绍了如何从零开始用django建立一个项目并且初步运行以来了, 现在我们就要开始写我们的html了,也就是django里面的模板了,不过这节我们只讲如何链接图片和css(静 ...
- java生成缩略图,旋转,水印,截图
转自:http://rensanning.iteye.com/blog/1545708 感谢,方便自己查看
- 《java并发编程实战》读书笔记11--构建自定义的同步工具,条件队列,Condition,AQS
第14章 构建自定义的同步工具 本章将介绍实现状态依赖性的各种选择,以及在使用平台提供的状态依赖机制时需要遵守的各项规则. 14.1 状态依赖性的管理 对于并发对象上依赖状态的方法,虽然有时候在前提条 ...
- 关于在C#中对类中的隐藏基类方法和重写方法的理解
最近在学习C#,在C#中的类看到重写和隐藏基类的方法这些概念.才开始感觉自己不是很理解这些概念.也区分不开这些概念.通过自己的查找资料和练习后.慢慢的理解了类中的隐藏和重写这个概念.在C#中只有在基类 ...