アリのアルゴリズムの内はペンの試験問題を押します

5621 ワード

#include 
#include 
#include 
#include
#include 
#include 
#include 
#include 
#define pi 3.1415926
#define NUM 10000
using namespace std;

/**          ,          **/
 /**   ,              ,           ^-^  **/
double cal(double x,double mul,double sigma)          //        
{
    double t=sqrt(2*pi);
    double t1=-(x-mul)*(x-mul)/(2*sigma*sigma);
    double f=t*exp(t1);
    return f;
}
bool inside(double x,double y)                   //       
{
    double a=(x*x+y*y-1)*(x*x+y*y-1)*(x*x+y*y-1)-x*x*y*y*y;
    if(a<=0)
        return true;
    else
        return false;
}

double randgass(double minvalue, double maxvalue,double miu, double sigma){//       
    double x,y,dscope;
    do{
        x=minvalue+(maxvalue-minvalue)*rand()/(RAND_MAX+1.0);
        y=cal(miu,miu,sigma);
        dscope=y*rand()/(RAND_MAX+1.0);
    }while(yreturn x;
}

double leartCurve(double mu1, double sigma1, double mu2, double sigma2) {
    double xrange=mu1-3*sigma1;
    double xsplit=6*sigma1;
    double yrange=mu2-3*sigma2;
    double ysplit=6*sigma2;
    double res=0;
    double xp=0,yp=0;
    int num=0;
    srand((unsigned)time(NULL));
    for(int i=0;iif (inside(xp,yp)) num++;
    }
    res=(double)num/NUM;
    return res;
}

int main() {
    double res;

    double _mu1;
    cin >> _mu1;
    //cin.ignore (std::numeric_limits<:streamsize>::max(), '
');
double _sigma1; cin >> _sigma1; //cin.ignore (std::numeric_limits<:streamsize>::max(), '
');
double _mu2; cin >> _mu2; //cin.ignore (std::numeric_limits<:streamsize>::max(), '
');
double _sigma2; cin >> _sigma2; //cin.ignore (std::numeric_limits<:streamsize>::max(), '
');
res = leartCurve(_mu1, _sigma1, _mu2, _sigma2); cout << res << endl; return 0; }