HDU 4586 Play the Dice (数学,公式推导)

题意:给定一个n面均匀的筛子,每个面都有一个值,另外有m面如果投到会有再投一次的机会(可以投无限此),问你他的概率是多少

解题代码:这是一个递推关系式,设答案为ans  则每一面有1/n的几率,分开算期望,如果一个面是m中的一个 它的期望是 1/n(a[x] + ans),最后即可求得关系式

解题代码:

 1 // File Name: 4686.c
 2 // Author: darkdream
 3 // Created Time: 2013年08月17日 星期六 19时46分29秒
 4 
 5 #include<stdio.h>
 6 #include<string.h>
 7 #include<stdlib.h>
 8 #include<time.h>
 9 #include<math.h>
10 #include<ctype.h>
11 int a[2000];
12 int b[2000];
13 int main(){
14 
15    //freopen("/home/plac/problem/input.txt","r",stdin);
16    //freopen("/home/plac/problem/output.txt","w",stdout);
17    int n , m;  
18    while(scanf("%d",&n) != EOF)
19    {
20       int sum = 0 ; 
21       for(int i =1 ;i<= n;i ++)
22       {
23           scanf("%d",&a[i]);
24           sum += a[i];
25       }
26       int temp ;
27       scanf("%d",&m);
28       for(int i= 1 ;i <= m;i ++)
29           scanf("%d",&temp);
30       if(sum == 0 )
31           printf("0.00
");
32       else if(n == m)
33           printf("inf
");
34       else printf("%.2lf
",sum*1.0/(n-m));
35 
36    }
37 return 0 ;
38 }
View Code
没有梦想,何谈远方
原文地址:https://www.cnblogs.com/zyue/p/3265032.html