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回合以内结束的概率是多少呢?

公式:

\[P(i) = \prod_{1}^{n}\left(1 - {{P}_{2i}}^{{k}_{i}} \right) , \sum_{1}^{n}{k}_{i} = i
\]

P2i = (1-P[i]),表示选不中这个人的概率

显然(1-P2i^k)表示k回合内至少选中一次这个人的概率

所以我们就贪心的选择+1次之后概率最大的那个人去猜就好了

然后再扫一遍统计答案就好了

直接暴力300000次,玄学暴力,当然这个是可以证明误差是正确的

代码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 120;
  4. priority_queue<pair<double,int> >Q;
  5. double p[maxn];
  6. double p2[maxn];
  7. int cnt[maxn];
  8. double ans[300000];
  9. int n;
  10. double quickpow(double m,long long n)//返回m^n
  11. {
  12. double b = 1.0;
  13. while (n > 0)
  14. {
  15. if (n & 1)
  16. b = (b*m);
  17. n = n >> 1 ;
  18. m = (m*m);
  19. }
  20. return b;
  21. }
  22. double deal(int x)
  23. {
  24. return (1-quickpow(p2[x],cnt[x]+1))/(1-quickpow(p2[x],cnt[x]));
  25. }
  26. double Count(int x)
  27. {
  28. return (1-quickpow(p2[x],cnt[x]));
  29. }
  30. int main()
  31. {
  32. scanf("%d",&n);
  33. for(int i=1;i<=n;i++)
  34. {
  35. scanf("%lf",&p[i]);
  36. p[i]/=100;
  37. p2[i]=1-p[i];
  38. }
  39. for(int step=1;step<300000;step++)
  40. {
  41. double Max = deal(1);
  42. int tmp = 1;
  43. for(int i=1;i<=n;i++)
  44. {
  45. if(cnt[i]==0)
  46. {
  47. tmp = i;
  48. break;
  49. }
  50. if(deal(i)>Max)
  51. Max=deal(i),tmp=i;
  52. }
  53. cnt[tmp]++;
  54. double pro = 1;
  55. for(int i=1;i<=n;i++)
  56. pro=pro*Count(i);
  57. ans[step]=pro;
  58. }
  59. double ans2 = 0;
  60. for(int i=1;i<300000;i++)
  61. ans2+=1.0*i*(ans[i]-ans[i-1]);
  62. printf("%.12f\n",ans2);
  63. }

AIM Tech Round (Div. 1) D. Birthday 数学 暴力的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. AIM Tech Round (Div. 2) A. Save Luke 水题

    A. Save Luke 题目连接: http://codeforces.com/contest/624/problem/A Description Luke Skywalker got locked ...

  5. Codeforces AIM Tech Round (Div. 2)

    这是我第一次完整地参加codeforces的比赛! 成绩 news standings中第50. 我觉这个成绩不太好.我前半小时就过了前三题,但后面的两题不难,却乱搞了1.5h都没有什么结果,然后在等 ...

  6. 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 ...

  7. 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 ...

  8. AIM Tech Round (Div. 1) C. Electric Charges 二分

    C. Electric Charges 题目连接: http://www.codeforces.com/contest/623/problem/C Description Programmer Sas ...

  9. 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 ...

随机推荐

  1. 采用dlopen、dlsym、dlclose加载动态链接库【转】

    转自:http://www.cnblogs.com/Anker/p/3746802.html 1.前言 为了使程序方便扩展,具备通用性,可以采用插件形式.采用异步事件驱动模型,保证主程序逻辑不变,将各 ...

  2. Linux I2C(一)之常用的几种实例化(i2c_client ) 【转】

    转自:http://blog.csdn.net/lugandong/article/details/48092397 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 前言 方式 ...

  3. hadoop环境搭建编译

    安装: JDK1.7+ maven 3.0 or later findbugs 1.3.9 protocolBuffer 2.5.0 cmake 2.6 zlib-devel openssl-deve ...

  4. android studio 64位手机+Fresco引起的在arm64位机器上找不到对应的so库

    我们的程序在32位机器上没有问题,有一天公司采购了一台魅族MX5 MTK的64位处理器上我们的应用报错了 "nativeLibraryDirectories=[/data/app/com.l ...

  5. input标签获取焦点时文本框内提示信息清空背景颜色发生变化

    <input type="text" id="username" onfocus="myFocus(this,'#f4eaf1')" ...

  6. 虚拟机 VMware Workstation12 安装OS X 系统

      Windows下虚拟机安装Mac OS X —– VMware Workstation12安装Mac OS X 10.11 本文即将介绍WIN虚拟MAC的教程.完整详细教程(包含安装中的一些问题) ...

  7. Java单线程多实例和多线程多实例

    最近写了一个程序,是采用多线程往redis里面写入数据,想统计一下一共写了多少条数据,于是用了一个static的全局变量count来累加,这块代码抽象出来就是这样的: public class Mul ...

  8. Majority Element——算法课上的一道题(经典)

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  9. GITHUB个人博客搭建-Pelican 在Windows环境下的安装及配置

    GITHUB个人博客搭建-Pelican 在Windows环境下的安装及配置 前言 此篇博客主要为Pelican在Windows平台下的配置安装所写,在此过程中主要参考资料烟雨林博客.poem_of_ ...

  10. 五十八 数据库访问使用SQLite

    SQLite是一种嵌入式数据库,它的数据库就是一个文件.由于SQLite本身是C写的,而且体积很小,所以,经常被集成到各种应用程序中,甚至在iOS和Android的App中都可以集成. Python就 ...