Combination Mathematics of Goal Probability

Number of goals


Title description

The Super League continues. Guangzhou Evergrande and Beijing Guoan will start the match immediately. The match lasts for 90 minutes. For the convenience of analysis, we take 5 minutes as a time slice, and the match will have 18 time slices. In each time slice, the probability of Evergrande scoring 1 goal is A%, and the probability of Guoan scoring 1 goal is B%. When the game is over, what is the probability that at least one of the two teams will score a prime number?

Input format

The first line, an integer R, indicates that there are R groups of test data. 1 <= R <= 10.

Each test data format:

The first line, A and B. 0 <= A <= 100, 0 <= B <= 100.

Output format

A total of R lines, each line has a real number, which represents the probability.

Input sample

3
50  50
100  100
12  89

Sample output

0.5265618908306351
0.0
0.6772047168840167

Problem solving ideas

The main idea: What is the probability that at least one team will score a prime number in 18 time segments?

According to the meaning of the question, to simplify the problem , we first consider the probability of a team's goals being a prime number .

If the number of goals scored by a team is a prime number, then the number of goals scored by this team can only be 2 , 3 , 5 , 7 , 11 , 13, 17, and continue to simplify the problem . This team has scored 2 goals. Then the team scored 2 goals in 18 time segments as follows:

Situation\Time Fragment 1 2 3 4 5 6 …… 17 18
1 √ √ √ √ × × × × × × × × × × × × × × × × × × × × ×
2 √ √ × × × √ √ × × × × × × × × × × × × × × × × × ×
… … …… … … …… … … …… … … …… … … …… … … …… … … …… … … …… … … …… … … ……
18 × × × × × × × × × × × × × × × × × × × × × √ √ √ √

Wow! The scale of this table is too big!

How many such situations are there? Can it be calculated by calculation? Observing carefully, we can find that this is not the number of combinations ! This is equivalent to choosing 2 from 18 balls: C 18 2 C^{2}_{18}C182

Among the 18 time segments, only 2 time segments score goals, and the other time segments cannot score goals . In this case, C 18 2 C^{2}_{18}C182Species, so let the probability of a goal be P (goal) P(goal)P ( g o a l ) , the probability that the team scores 2 goals in 18 time segments is: C 18 2 × P (goal) 2 × (1 − P (goal)) 16 C^{2} _{18}\times P(goal)^2 \times(1-P(goal))^{16}C182×P(goal)2×(1P(goal))16

It can be seen that the number of goals iiThe number of combinations corresponding to i isC 18 i C^{i}_{18}C18i, The probability algorithm is the same as above: C 18 i × P (goal) i × (1 − P (goal)) 18 − i C^{i}_{18}\times P(goal)^i \times(1 -P(goal))^{18-i}C18i×P(goal)i×(1P(goal))1 8 i (The number of combinations can bepreprocessed byYanghui triangle).

Now, let’s go back to the original question. Find the probability that at least one team will score a prime number . Let’s discuss it first :

  1. Evergrande’s goals are prime, while Guoan’s goals are non-prime.
  2. Evergrande’s goals are non-prime, Guoan’s goals are prime
  3. The number of goals scored by Evergrande is a prime number, and the number of goals scored by Guoan is a prime number

The probabilities of the above three cases are calculated and added together, and this is the answer. However, there is an easier way.

The probability that at least one team scores a prime number = 1-the probability that both teams score a non-prime number

This is much more convenient.


Code:

#include<iostream>
#include<fstream>
#include<algorithm>
#include<iomanip>

using namespace std;
int R,A,B;
long long C[25][25];
int composite[25]={
    
    0,1,4,6,8,9,10,12,14,15,16,18};//合数集合
double hd[25],ga[25],temp1,temp2,ans;

void init()
{
    
    
	for(int i=0;i<=18;i++)
	{
    
    
		C[i][0]=1;
		C[i][i]=1;
	}
	for(int i=1;i<=18;i++)
		for(int j=1;j<i;j++)
			C[i][j]=C[i-1][j-1]+C[i-1][j];
}


int main()
{
    
    
	freopen("1265.in","r",stdin);
	freopen("1265.out","w",stdout);
	init();
     cin>>R;
	 for(int r=1;r<=R;r++)
	 {
    
    
		 ans=0;
		 cin>>A>>B;
		 for(int i=0;i<=18;i++)
		 {
    
    
			temp1=temp2=1;
			for(int j=1;j<=i;j++)
				temp1*=(double(A)*0.01);
			for(int j=1;j<=18-i;j++)
				temp2*=(1.00-double(A)*0.01);
			hd[i]=double(C[18][i])*temp1*temp2;//恒大
			
			temp1=temp2=1;
			for(int j=1;j<=i;j++)
				temp1*=(double(B)*0.01);
			for(int j=1;j<=18-i;j++)
				temp2*=(1.00-double(B)*0.01);
			ga[i]=double(C[18][i])*temp1*temp2;//国安
		 }
		 for(int i=0;i<=11;i++)
			 for(int j=0;j<=11;j++)
				 ans+=hd[composite[i]]*ga[composite[j]];
		 ans=1.00-ans;
		 cout<<fixed<<setprecision(7)<<ans<<endl;
	 }

    return 0;
}

Guess you like

Origin blog.csdn.net/bell041030/article/details/88906510