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\n");
32       else if(n == m)
33           printf("inf\n");
34       else printf("%.2lf\n",sum*1.0/(n-m));
35 
36    }
37 return 0 ;
38 }
View Code

 

转载于:https://www.cnblogs.com/zyue/p/3265032.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值