Pagini recente » Cod sursa (job #44158) | Cod sursa (job #1422567) | Cod sursa (job #828290) | Cod sursa (job #57568) | Cod sursa (job #637184)
Cod sursa(job #637184)
#include <fstream>
#include <ctime>
#include <cstring>
#include <cstdlib>
using namespace std;
int t,total,x,y,i,n,a[30];
double s;
int main()
{
ifstream fi("minesweeper.in");
ofstream fo("minesweeper.out");
srand(time(NULL));
fi>>x>>y;
n=x*y;
for(i=1;i<=n;i++)
{
t=0;
memset(a,0,sizeof(a));
total=0;
while(1)
{
t++;
x=(rand()%(2*n-1))/2;
x++;
a[x]=(a[x]+1)%3;
if(a[x]==0) total--; else
if(a[x]==2) total++;
if(total==n) break;
}
s+=t;
}
s=(double)s/(double)(n);
fo<<s<<"\n";
return 0;
}