美团CodeM2018资格赛赛题官方版本详解(三)——世界杯





解题思路

标准程序

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <iostream>
#include <algorithm>

using namespace std;

double v[6][16][16], p[16][16];

int main() {
    for (int i = 0; i < 16; i++)
        for (int j = 0; j < 16; j++)
            scanf("%lf", &p[i][j]);
    memset(v, 0, sizeof(v));
    for (int i = 0; i < 16; i++)
        v[0][i][0] = 1.0;
    for (int i = 1; i <= 4; i++)
        for (int j = 0; j < 16 >> i; j++) {
            for (int x = 0; x < 1 << (i - 1); x++)
                for (int y = 0; y < 1 << (i - 1); y++)
                    v[i][j][x] += v[i - 1][j << 1][x] * v[i - 1][(j << 1) + 1][y] * p[(j << i) + x][(j << i) + (1 << (i - 1)) + y],
                    v[i][j][(1 << (i - 1)) + y] += v[i - 1][j << 1][x] * v[i - 1][(j << 1) + 1][y] * (1.0 - p[(j << i) + x][(j << i) + (1 << (i - 1)) + y]);
            }
    for (int i = 0; i < 16; i++)
        printf("%.10f%c", v[4][0][i], i == 15 ? '\n' : ' ');
}

猜你喜欢

转载自blog.csdn.net/m0_38068229/article/details/80671536
今日推荐