Cod sursa(job #635318)

Utilizator cont_de_testeCont Teste cont_de_teste Data 19 noiembrie 2011 10:17:27
Problema Minesweeper Scor 10
Compilator cpp Status done
Runda .com 2011 Marime 0.79 kb
# include <cstdio>
# include <ctime>
# include <cstring>
# include <cstdlib>

const char *FIN = "minesweeper.in", *FOU = "minesweeper.out";
const int MAX = 22;

int N, M, V[5], A[MAX][MAX];

inline double doit (void) {
    memset (A, 0, sizeof (A));
    memset (V, 0, sizeof (V));

    double time = 0;
    for (V[0] = N * M; V[2] != N * M; time += 1) {
        int i = rand () % N + 1, j = rand () % M + 1;
        V[A[i][j]] -= 1;
        V[A[i][j] += (A[i][j] != 2 ? 1 : -2)] += 1;
    }
    //printf ("%lf ", time);
    return time;
}


int main (void) {
    srand (time (NULL));

    fscanf (fopen (FIN, "r"), "%d %d", &N, &M);

    double sum = 0;
    for (int i = 1; i <= 100000; ++i)
        sum += doit ();
    fprintf (fopen (FOU, "w"), "%lf", sum / 100000.0);
}