mental_assessment
A confirmatory program about one example from school's mathematical
modeling class.
C++.
SC
#include<bits/stdc++.h>
#include<iostream>
#include<Windows.h>
#include<math.h>
#pragma GCC optimize(3,"Ofast","inline")
//#pragma GCC optimize(3)
using namespace std;
const int N=31;
short int ct[N][N][N];
int a[N];
inline int read(){
int ck=0;
char fu=1;
char c;
for(;!isdigit(c);c=getchar())
if(c=='-')
fu=-1;
for(;isdigit(c);c=getchar())
ck=ck*10+c-'0';
return fu*ck;
}
void qsort(int l,int r){
int mid=a[(l+r)/2];
int i=l,j=r;
do{
while(a[i]<mid)
i++;
while(a[j]>mid)
j--;
if(i<=j){
swap(a[i],a[j]);
i++;
j--;
}
}while(i<=j);
if(l<j)
qsort(l,j);
if(i<r)
qsort(i,r);
}
struct ans{
double normal, tic, minia;
};
int qu(int x){
if(x>=0)
return x;
return x*-1;
}
double yy=100.0000;
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// srand(time(0));
double totalnormal=0,totaltic=0,totalminia=0;
double meantotalnormal=0, meantotaltic=0, meantotalminia=0;
memset(ct,0,sizeof(ct));
double flag=0;
ans answer;
double n=0;
cout<<"Please enter the number of times you want to simulate"<<endl;
cout<<"!!!"<<endl;
cout<<"Remember! for each times of simulation, the program will process 1e9 times random data."<<endl;
cout<<"You had better enter a number less than 40."<<endl;
cout<<"And please wait with patience."<<endl;
cin>>n;
int start=time(0);
srand(time(0));
for(int acc=1;acc<=n;acc++){
for(double i=0;i<=100;i++){
for(double j=0;i+j<=100;j++){
//cout<<"h1"<<endl;
double k=100-i-j;
int normal=0, tic=0, minia=0;
for(int t=1;t<=200;t++){
for(int f=1;f<=30;f++){
int p=rand()%100;
//cout<<p<<endl;
if(p<i)
normal++;
if(p>=i&&p<i+j)
tic++;
if(p>=i+j&&p<=99)
minia++;
}
ct[normal][tic][minia]++;
normal=0;
tic=0;
minia=0;
}
if(ct[8][10][12]>flag){
flag=ct[8][10][12];
answer.normal=i;
answer.tic=j;
answer.minia=k;
}
//cout<<"h3"<<endl;
memset(ct,0,sizeof(ct));
}
}
cout<<answer.normal/yy<<" "<<answer.tic/yy<<" "<<answer.minia/yy<<" "<<endl;
totalnormal+=answer.normal;
totaltic+=answer.tic;
totalminia+=answer.minia;
flag=0;
}
//cout<<meantotaltic<<endl;
meantotalnormal=totalnormal/n;
meantotaltic=totaltic/n;
meantotalminia=totalminia/n;
cout<<"average: "<<endl;
cout<<"normal: "<<meantotalnormal/yy<<endl;
cout<<"tic: "<<meantotaltic/yy<<endl;
cout<<"minia: "<<meantotalminia/yy<<endl;
int timecost=time(0)-start;
cout<<"time cost= "<<timecost<<endl;
system("pause");
return 0;
}