Cod sursa(job #637494)

Utilizator savimSerban Andrei Stan savim Data 20 noiembrie 2011 14:48:45
Problema Minesweeper Scor 40
Compilator cpp Status done
Runda .com 2011 Marime 0.84 kb
#include <fstream>

using namespace std;

ifstream f("minesweeper.in");
ofstream g("minesweeper.out");

#define MAX_N 25

int x, y, n;

double c[2][MAX_N][MAX_N];

void solve() {
    c[0][n][0] = 1;

    double ans = 0;

    int l = 0;
    for (int steps = 1; steps <= 100000; steps++) {
        for (int i = 0; i <= n; i++)
            for (int j = 0; i + j <= n; j++) {
                if (!(i == 0 && j == 0)) {
                    c[1 ^ l][i - 1][j + 1] += c[l][i][j] * i / n;
                    c[1 ^ l][i][j - 1] += c[l][i][j] * j / n;

                    c[1 ^ l][i + 1][j] += c[l][i][j] * (n - i - j) / n;
                }
            
                c[l][i][j] = 0;
            }
        
        l ^= 1;

        ans += c[l][0][0] * steps;
    }

    g << ans << "\n";
}

int main() {

    f >> x >> y; n = x * y;

    solve();

    return 0;
}