假设有两名球员,假设A和B都试图赢得比赛的点球。给定四个整数变量a,b,c,d,因此A首先获得惩罚的概率为a / b,而B首先获得惩罚的概率为c / d。
首先得分的人将赢得比赛,根据给定的问题陈述程序,必须找到A赢得比赛的可能性。
输入项
a = 10, b = 20, c = 30, d = 40
输出结果
probability is 0.5333
输入项
a = 1, b = 2, c = 10, d = 11
输出结果
probability is 0.523
输入四个整数变量a,b,c,d的值
从总概率中减去B赢得比赛的概率,我们将得出A赢得比赛的结果概率
e *(1 /(1-(1-f)*(1-f))))
其中,e是A赢得比赛的概率,f是B赢得比赛的概率
显示A赢得比赛的概率
Start Step 1→ Declare function to calculate the probability of winning double probab_win(int a, int b, int c, int d) Declare double e = (double)a / (double)b Declare double f = (double)c / (double)d return (e * (1 / (1 - (1 - f) * (1 - f)))) Step 2→ In main() Declare variable as int a = 10, b = 20, c = 30, d = 40 Call probab_win(a, b, c, d) Stop
#include <bits/stdc++.h> using namespace std; //计算赢得比赛的可能性 double probab_win(int a, int b, int c, int d){ double e = (double)a / (double)b; double f = (double)c / (double)d; return (e * (1 / (1 - (1 - f) * (1 - f)))); } int main(){ int a = 10, b = 20, c = 30, d = 40; cout<<"probability is "<<probab_win(a, b, c, d); return 0; }
输出结果
如果运行上面的代码,它将生成以下输出-
probability is 0.5333