Pagini recente » Cod sursa (job #300534) | Cod sursa (job #3168906) | Cod sursa (job #264624) | Cod sursa (job #1266945) | Cod sursa (job #637696)
Cod sursa(job #637696)
# 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;
int i = 0;
for (V[0] = N * M; i < 10000 && V[2] != N * M; ++i, 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);
}