题目链接 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;
}