solution.md 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
# 夺冠概率
足球比赛具有一定程度的偶然性,弱队也有战胜强队的可能。

假设有甲、乙、丙、丁四个球队。根据他们过去比赛的成绩,得出每个队与另一个队对阵时取胜的概率表:
```
    甲   乙  丙  丁   
甲   -  0.1 0.3 0.5
乙 0.9  -   0.7 0.4 
丙 0.7  0.3 -   0.2
丁 0.5  0.6 0.8 -
```
数据含义:甲对乙的取胜概率为0.1,丙对乙的胜率为0.3,...

现在要举行一次锦标赛。双方抽签,分两个组比,获胜的两个队再争夺冠军。

![](https://img-blog.csdn.net/20150228234310457?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvd3IxMzI=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)

请你进行10万次模拟,计算出甲队夺冠的概率。

 

## aop
### before
```cpp
#include <iostream>
using namespace std;
double rate[4][4] = {
    {0, 0.1, 0.3, 0.5},
    {0.9, 0, 0.7, 0.4},
    {0.7, 0.3, 0, 0.2},
    {0.5, 0.6, 0.8, 0}};
```
### after
```cpp

```

## 答案
```cpp
int main()
{
    int i, j, k;
    double time, sum;
    time = 0;
    sum = 0;
    for (i = 1; i < 4; i++)
    {
        for (j = 1; j < 4; j++)
        {
            for (k = 1; k < 4; k++)
            {
                if (j != i && k != i && j != k)
                {
                    sum += rate[0][i] * rate[j][k] * rate[0][j];
                }
            }
        }
        time++;
    }
    cout << sum / time;
    return 0;
}
```
## 选项

### A
```cpp
int main()
{
    int i, j, k;
    double time, sum;
    time = 0;
    sum = 0;
    for (i = 1; i < 4; i++)
    {
        for (j = 1; j < 4; j++)
        {
            for (k = 1; k < 4; k++)
            {
                if (j != i && k != i && j != k)
                {
                    sum += rate[0][i] * rate[0][j];
                }
            }
        }
        time++;
    }
    cout << sum / time;
    return 0;
}
```

### B
```cpp
int main()
{
    int i, j, k;
    double time, sum;
    time = 0;
    sum = 0;
    for (i = 1; i < 4; i++)
    {
        for (j = 1; j < 4; j++)
        {
            for (k = 1; k < 4; k++)
            {
                if (j != i && k != i && j != k)
                {
                    sum += rate[j][k] * rate[0][j];
                }
            }
        }
        time++;
    }
    cout << sum / time;
    return 0;
}
```

### C
```cpp
int main()
{
    int i, j, k;
    double time, sum;
    time = 0;
    sum = 0;
    for (i = 1; i < 4; i++)
    {
        for (j = 1; j < 4; j++)
        {
            for (k = 1; k < 4; k++)
            {
                if (j != i && k != i && j != k)
                {
                    sum += rate[0][i] * rate[j][k];
                }
            }
        }
        time++;
    }
    cout << sum / time;
    return 0;
}
```