赛后补题 North America Qualifier (2015) B Bobby's Bet

题目链接 Bobby’s Bet
有一说一,英语太菜了,看不懂题。。
题意 掷色子,有s个面,值是1-s,掷y次,如果有至少x次所得的值 >= r 那么就给bobby w个钱,反之给Betty 1个钱,问值不值得赌。
就是个求数学期望的问题,w乘以至少x次所得值>= r 的概率即可,其中涉及到组合数的知识,会专门写一篇或者转载一篇来记录。
代码

#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

int countt;

int  comb1(int m,int k)//求组合数
{
    int i;
    for (i=m;i>=k;i--){
        if (k>1){
            comb1(i-1,k-1);
        }
        else{
            countt++;
        }
     }
     return countt;
}

int main()
{
    int n;
    cin>>n;
    while(n--){
        int r,s,x,y,w;
        cin>>r>>s>>x>>y>>w;
        double p = (s - r + 1) * 1.0 / s,p1,ans = 0;
        int num;
        for(int i=x; i<=y; i++){
            int c = y-i;
            p1 = 1.0;
            double p2 = 1.0-p;
            while(c--){
                p1 *= p2;
            }
            int cc = i;
            double P = 1.0;
            for(int j = 1; j <= i; j++){
                P *= p;
            }
            countt = 0;
            num = comb1(y,i);
            ans += P * p1 * num;//每一次的概率的和才是掷y次至少x次所得的值 >= r的概率 
        }
        if(w * ans > 1){//如果期望大于1
            cout<<"yes"<<endl;
        }
        else{
            cout<<"no"<<endl;
        }
    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值