Pagini recente » Cod sursa (job #2542447) | Cod sursa (job #300188) | Cod sursa (job #2970196) | Cod sursa (job #1860911) | Cod sursa (job #636026)
Cod sursa(job #636026)
#include <fstream>
#include <iomanip>
#include <cstdlib>
using namespace std;
ifstream fin("minesweeper.in");
ofstream fout("minesweeper.out");
int N , M , D[16][16] , nr , timp , t , nm;
void f(int x,int y)
{
if(nr==nm) return;
t++;
if(D[x][y]==1) D[x][y] = 2 , nr++;
else
if(D[x][y]==2) D[x][y] = 0 , nr--;
else
D[x][y]++;
f(rand() % N + 1,rand()%M + 1);
}
int main()
{
fin>>N>>M;
nm = N*M;
for(int i=1;i<=100000;++i)
{
t = 0;
f(rand()%N + 1 ,rand()%M+1);
timp+=t; t= 0;
for(int x=1;x<=N;++x)
for(int y=1;y<=M;++y)
D[x][y] = 0;
nr = 0;
}
fout<<fixed<<setprecision(6)<<(double)timp/100000;
return 0;
}