Beispiel #1
0
 bool sol3(TreeNode *root, TreeNode *minNode, TreeNode *maxNode)
 {
     if (!root)
         return true;
     if ((minNode && root->val <= minNode->val) || (maxNode && root->val>= maxNode->val))
         return false;
     return sol3(root->left, minNode, root) && sol3(root->right, root, maxNode);
 }
Beispiel #2
0
int main()
{
    eoPop<DualVector> pop;

    // fixed test
    DualVector sol1(2,-1);
    DualVector sol2(2,-1);
    DualVector sol3(2,1);
    DualVector sol4(2,1);
    pop.push_back( sol1 );
    pop.push_back( sol2 );
    pop.push_back( sol3 );
    pop.push_back( sol4 );
    // on the sphere function everyone has the same fitness of 1
    if( test(pop, 0) != 0 ) {
        exit(1);
    }

    pop.erase(pop.begin(),pop.end());

    // fixed test
    sol1 = DualVector(2,0);
    sol2 = DualVector(2,0);
    sol3 = DualVector(2,1);
    sol4 = DualVector(2,1);
    pop.push_back( sol1 );
    pop.push_back( sol2 );
    pop.push_back( sol3 );
    pop.push_back( sol4 );
    if( test(pop, 1) != 1 ) {
        exit(1);
    }

    // test on a random normal distribution
    eoNormalGenerator<double> normal(1,rng);
    eoInitFixedLength<DualVector> init_N(2, normal);
    pop = eoPop<DualVector>( 1000000, init_N );
    double iqr = test(pop, 1.09);
    if( iqr < 1.08 || iqr > 1.11 ) {
        exit(1);
    }
}
Beispiel #3
0
void sol4()  //根据控制点,求曲线上的m个点  
{  
    int m=500,i;  
    for(i=0;i<=m;i++)  
    sol3((double)i/(double)m);  
}  
Beispiel #4
0
 bool isValidBST(TreeNode* root) {
     return sol3(root, NULL, NULL);
 }