1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
int main()
{
double P[2][2]={{1,0.5},
{0.5,1}};
int A[2]={1,1};
int Mem_in[50000][5];
int sizeofA=2;
int sizeof_Mem_in=0;
clock_t t1,t2;
t1=clock();
for(int i=0;i<10000;i++)
{
arrive(Mem_in,A,P,sizeofA,sizeof_Mem_in );
//print(Mem_in,sizeof_Mem_in,5);
}
t2=clock();
double dif = (double)(t2-t1)/CLOCKS_PER_SEC ;
cout<<"dif "<<dif;
cout<<"epistrofi";
//print(Mem_in,5,5);*/
int a;
cin>>a;
}
ostream & print(const int v[10000][5],int rows,int columns)
{
for (int i=0; i<rows; i++)
{
for (int j=0; j<columns; j++)
cout << v[i][j] << ' ';
cout << endl;
}
return cout;
}
void arrive(int Mem_in[10000][5],const int *A,const double P[2][2],int sizeofA,int &sizeof_Mem_in )
{
int M=sizeofA;
for (int i=0;i<M;i++)
{
for (int k=0;k<A[i];k++)
{
sizeof_Mem_in+=1;
Mem_in[sizeof_Mem_in-1][0]=find_Column_Max(Mem_in,0,sizeof_Mem_in-1)+1;
Mem_in[sizeof_Mem_in-1][1]=i+1;
Mem_in[sizeof_Mem_in-1][2]=1;
change_row_elements(Mem_in,sizeof_Mem_in-1,3,M+2,P[i]);
//cout<<"ektiposi"<<Mem_in[i+k][0]<<Mem_in[i+k][1]<<Mem_in[i+k][2]<<Mem_in[i+k][3]<<Mem_in[i+k][4]<<endl;
}
}
int asxeto;
}
int find_Column_Max(const int diplospinakas[10000][5],int column,const int sizeof_diplospinakas)
{
if(sizeof_diplospinakas==0) return 0;
int max=diplospinakas[0][column];
for(int i=0;i<sizeof_diplospinakas;i++)
{
if(diplospinakas[i][column]>max) max=diplospinakas[i][column];
}
return max;
}
void change_row_elements(int diplospinakas[10000][5],int row,int first_column,int last_column,const double *P)
{
int Pcolumn=0;
for(int j=first_column;j<=last_column;j++)
{
diplospinakas[row][j]=get_resultof_probability(P[Pcolumn]);
Pcolumn++;
}
}
int get_resultof_probability(double prob)
{
double anumber_0_1=(rand()%1000)/1000.0;
if(anumber_0_1<prob)
{
//cout<<1<<endl;
return 1;
}
else
{
//cout<<0<<endl;
return 0;
}
}
}
| |