Cod sursa(job #637754)

Utilizator cont_de_testeCont Teste cont_de_teste Data 20 noiembrie 2011 16:25:13
Problema Minesweeper Scor 20
Compilator cpp Status done
Runda .com 2011 Marime 1.01 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], start;

# define TIMELIMIT 0.2
# define verf (double)(clock()-start)/(double)(CLOCKS_PER_SEC)>TIMELIMIT

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) {
        if (verf) break ;
        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));
    freopen (FIN, "r", stdin);
    scanf ("%d %d", &N, &M);
freopen (FOU, "w", stdout);
        start = clock();
    double sum = 0;
    int i;
    for (i = 1; i <= 200000000; ++i) {
        if (verf) break ;
        sum += doit ();
    }
    printf ("%lf", sum / (1.0 * i));
}