Pagini recente » Cod sursa (job #1899538) | Cod sursa (job #151935) | Cod sursa (job #1344626) | Cod sursa (job #1242099) | Cod sursa (job #637754)
Cod sursa(job #637754)
# 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));
}