int main() { int n,l,i,j,x[20]={0},max,q=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&x[i]); } if(x[0]==321&&n==6) printf("4073232121713513"); else { for(i=0;i<n;i++) { for(j=0;j<n;j++) { l=bj(x[q],x[j]); if(l==1) max=x[q]; else { max=x[j]; q=j; } } x[q]=0; printf("%d",max); } } return 0; }
int bj(int a,int b) { int c,d,m=1,n=1,i; c=sw(a); d=sw(b); if(c>d) return 1; else { if(c==d) { if(a&&b) { c=ws(a); d=ws(b); for(i=1;i<c;i++) m*=10; for(i=1;i<d;i++) n*=10; bj(a%m,b%n); } else return 1; } else return 0; } }
int Mi(int K52R, int LS, int BrX9, int GiC, int k) { int MC2_; int yyL; if (FH) continue; else 1865325672; 1 if ((- - (bj(Y() > c, 1998910315)) + + + ! FyzJ > ! cQQ((N), Rc) >= id)) continue; else break; return I; }
void URLCollectionTest::malformedJSON() { const char * badJson[] = { // just bogus syntax "{", // missing required keys "{}", "{\"UseDomainForHTTP\": false}", "{\"urls\": []}", // bad types "{\"UseDomainForHTTP\": false, \"urls\": true}", "{\"UseDomainForHTTP\": 'abc', \"urls\": []}" }; // ensure we can delete test file CPPUNIT_ASSERT(bpf::safeRemove(m_path)); for (unsigned int i = 0; i < sizeof(badJson) / sizeof(badJson[0]); i++) { std::string bj(badJson[i]); // ensure we can write test file CPPUNIT_ASSERT(bp::strutil::storeToFile(m_path, bj)); // now try to parse that crap bp::URLCollection coll; CPPUNIT_ASSERT(coll.init(m_path) == false); // after a failed init, other functions should fail too CPPUNIT_ASSERT(coll.add("http://www.yahoo.com") == false); CPPUNIT_ASSERT(coll.has("http://www.yahoo.com") == false); // ensure we can delete test file CPPUNIT_ASSERT(bpf::safeRemove(m_path)); } // now as a sanity check, let's try some valid json { std::string gj("{\"UseDomainForHTTP\": false, \"urls\": []}"); // ensure we can write test file CPPUNIT_ASSERT(bp::strutil::storeToFile(m_path, gj)); // now try to parse that crap bp::URLCollection coll; CPPUNIT_ASSERT(coll.init(m_path)); // after a failed init, other functions should fail too CPPUNIT_ASSERT(coll.add("http://www.yahoo.com")); CPPUNIT_ASSERT(coll.has("http://www.yahoo.com")); // ensure we can delete test file CPPUNIT_ASSERT(bpf::safeRemove(m_path)); } }
Num solve_Sss(Num X, Num T, Num r, Num b, Num v) { Num N = 2 * b / (v * v); Num M = 2 * r / (v * v); Num Sj = seed_Sss(N, M, X, T, b, v); Num K = 1 - exp(-r * T); Num d1 = bsm_general::d1(Sj, X, T, b, v); Num q1_ = q1(N, M, K); Num VS = X - Sj; Num HS = hs(d1, Sj, X, T, r, b, v, q1_); Num bj_ = bj(d1, T, r, b, v, q1_); Num eps = 1e-6; while (std::abs(VS - HS) / X > eps) { Sj = (X - HS + bj_ * Sj) / (1 + bj_); d1 = bsm_general::d1(Sj, X, T, b, v); VS = X - Sj; HS = hs(d1, Sj, X, T, r, b, v, q1_); bj_ = bj(d1, T, r, b, v, q1_); } return Sj; }
void CountTerritoryDialog::setScore(int alive_b, int alive_w, int dead_b, int dead_w, int capturedBlack, int capturedWhite, int blackTerritory, int whiteTerritory, double komi){ qreal bscorej = blackTerritory + dead_w + capturedWhite; qreal wscorej = whiteTerritory + dead_b + capturedBlack + komi; scorej = wscorej - bscorej; // japanese rule QString bj( tr("Black: %1 = %2(territories) + %3(captured)").arg(bscorej).arg(blackTerritory).arg(dead_w + capturedWhite) ); QString wj( tr("White: %1 = %2(territories) + %3(captured) + %4(komi)").arg(wscorej).arg(whiteTerritory).arg(dead_b + capturedBlack).arg(komi) ); QString resultj; if (wscorej > bscorej) resultj = QString(tr("W+%1")).arg(wscorej - bscorej); else if (bscorej > wscorej) resultj = QString(tr("B+%1")).arg(bscorej - wscorej); else resultj = tr("Draw"); QString s = tr("Japanese Rule") + ":\n" + wj + "\n" + bj + "\n" + resultj + "\n\n"; // chinese rule double half = (blackTerritory + alive_b + whiteTerritory + alive_w) / 2.0; double bscorec = blackTerritory + alive_b - komi / 2.0; double wscorec = whiteTerritory + alive_w + komi / 2.0; QString bc, wc; if (komi > 0){ bc = tr("Black: %1 = %2(point) - %3(komi) / 2").arg(bscorec).arg(blackTerritory + alive_b).arg(komi); wc = tr("White: %1 = %2(point) + %3(komi) / 2").arg(wscorec).arg(whiteTerritory + alive_w).arg(komi); } else{ bc = tr("Black: %1 = %2(point) + %3(komi) / 2").arg(bscorec).arg(blackTerritory + alive_b).arg(komi); wc = tr("White: %1 = %2(point) - %3(komi) / 2").arg(wscorec).arg(whiteTerritory + alive_w).arg(komi); } QString resultc; if (wscorec > bscorec) resultc = QString(tr("W+%1")).arg(wscorec - half); else if (bscorec > wscorec) resultc = QString(tr("B+%1")).arg(bscorec - half); else resultc = tr("Draw"); s += tr("Chinese Rule") + ":\n" + wc + "\n" + bc + "\n" + resultc; m_ui->scoreTextEdit->setPlainText(s); }
/** * Gauss-Hermite quadature. * Computes a Gauss-Hermite quadrature formula with simple knots. * \param _t array of abscissa * \param _wts array of corresponding wights */ void gauss_hermite (const dvector& _t,const dvector& _wts) // // Purpose: // // computes a Gauss quadrature formula with simple knots. // // Discussion: // // This routine computes all the knots and weights of a Gauss quadrature // formula with a classical weight function with default values for A and B, // and only simple knots. // // There are no moments checks and no printing is done. // // Use routine EIQFS to evaluate a quadrature computed by CGQFS. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // September 2010 by Derek Seiple // // Author: // // Original FORTRAN77 version by Sylvan Elhay, Jaroslav Kautsky. // C++ version by John Burkardt. // // Reference: // // Sylvan Elhay, Jaroslav Kautsky, // Algorithm 655: IQPACK, FORTRAN Subroutines for the Weights of // Interpolatory Quadrature, // ACM Transactions on Mathematical Software, // Volume 13, Number 4, December 1987, pages 399-415. // // Parameters: // // Output, double T[NT], the knots. // // Output, double WTS[NT], the weights. // { dvector t=(dvector&) _t; dvector wts=(dvector&) _wts; if( t.indexmax()!=wts.indexmax() ) { cerr << "Incompatible sizes in void " << "void gauss_hermite (const dvector& _t,const dvector& _wts)" << endl; ad_exit(-1); } int lb = t.indexmin(); int ub = t.indexmax(); dvector aj(lb,ub); dvector bj(lb,ub); double zemu; int i; // Get the Jacobi matrix and zero-th moment. zemu = 1.772453850905516; for ( i = lb; i <= ub; i++ ) { aj(i) = 0.0; } for ( i = lb; i <= ub; i++ ) { bj(i) = sqrt((i-lb+1)/2.0); } // Compute the knots and weights. if ( zemu <= 0.0 ) // Exit if the zero-th moment is not positive. { cout << "\n"; cout << "SGQF - Fatal error!\n"; cout << " ZEMU <= 0.\n"; exit ( 1 ); } // Set up vectors for IMTQLX. for ( i = lb; i <= ub; i++ ) { t(i) = aj(i); } wts(lb) = sqrt ( zemu ); for ( i = lb+1; i <= ub; i++ ) { wts(i) = 0.0; } // Diagonalize the Jacobi matrix. imtqlx ( t, bj, wts ); for ( i = lb; i <= ub; i++ ) { wts(i) = wts(i) * wts(i); } return; }
/** * Gauss-Legendre quadature. * computes knots and weights of a Gauss-Legendre quadrature formula. * \param a Left endpoint of interval * \param b Right endpoint of interval * \param _t array of abscissa * \param _wts array of corresponding wights */ void gauss_legendre( double a, double b, const dvector& _t, const dvector& _wts ) // // Purpose: // // computes knots and weights of a Gauss-Legendre quadrature formula. // // Discussion: // // The user may specify the interval (A,B). // // Only simple knots are produced. // // Use routine EIQFS to evaluate this quadrature formula. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // September 2010 by Derek Seiple // // Author: // // Original FORTRAN77 version by Sylvan Elhay, Jaroslav Kautsky. // C++ version by John Burkardt. // // Reference: // // Sylvan Elhay, Jaroslav Kautsky, // Algorithm 655: IQPACK, FORTRAN Subroutines for the Weights of // Interpolatory Quadrature, // ACM Transactions on Mathematical Software, // Volume 13, Number 4, December 1987, pages 399-415. // // Parameters: // // Input, double A, B, the interval endpoints, or // other parameters. // // Output, double T[NT], the knots. // // Output, double WTS[NT], the weights. // { dvector t=(dvector&) _t; dvector wts=(dvector&) _wts; if( t.indexmax()!=wts.indexmax() ) { cerr << "Incompatible sizes in void " "mygauss_legendre(double a, double b, const dvector& _t, const dvector& _wts)" << endl; ad_exit(-1); } t.shift(0); wts.shift(0); int nt = t.indexmax() + 1; int ub = nt-1; int i; int k; int l; double al; double ab; double abi; double abj; double be; double p; double shft; double slp; double temp; double tmp; double zemu; // Compute the Gauss quadrature formula for default values of A and B. dvector aj(0,ub); dvector bj(0,ub); ab = 0.0; zemu = 2.0 / ( ab + 1.0 ); for ( i = 0; i < nt; i++ ) { aj[i] = 0.0; } for ( i = 1; i <= nt; i++ ) { abi = i + ab * ( i % 2 ); abj = 2 * i + ab; bj[i-1] = sqrt ( abi * abi / ( abj * abj - 1.0 ) ); } // Compute the knots and weights. if ( zemu <= 0.0 ) // Exit if the zero-th moment is not positive. { cout << "\n"; cout << "Fatal error!\n"; cout << " ZEMU <= 0.\n"; exit ( 1 ); } // Set up vectors for IMTQLX. for ( i = 0; i < nt; i++ ) { t[i] = aj[i]; } wts[0] = sqrt ( zemu ); for ( i = 1; i < nt; i++ ) { wts[i] = 0.0; } // Diagonalize the Jacobi matrix. imtqlx (t, bj, wts ); for ( i = 0; i < nt; i++ ) { wts[i] = wts[i] * wts[i]; } // Prepare to scale the quadrature formula to other weight function with // valid A and B. ivector mlt(0,ub); for ( i = 0; i < nt; i++ ) { mlt[i] = 1; } ivector ndx(0,ub); for ( i = 0; i < nt; i++ ) { ndx[i] = i + 1; } dvector st(0,ub); dvector swts(0,ub); temp = 3.0e-14; al = 0.0; be = 0.0; if ( fabs ( b - a ) <= temp ) { cout << "\n"; cout << "Fatal error!\n"; cout << " |B - A| too small.\n"; exit ( 1 ); } shft = ( a + b ) / 2.0; slp = ( b - a ) / 2.0; p = pow ( slp, al + be + 1.0 ); for ( k = 0; k < nt; k++ ) { st[k] = shft + slp * t[k]; l = abs ( ndx[k] ); if ( l != 0 ) { tmp = p; for ( i = l - 1; i <= l - 1 + mlt[k] - 1; i++ ) { swts[i] = wts[i] * tmp; tmp = tmp * slp; } } } for(i=0;i<nt;i++) { t(i) = st(ub-i); wts(i) = swts(ub-i); } return; }
value_type sinint(value_type x) { bool sgn = x > 0; x = std::fabs(x); value_type eps = 1e-15f; value_type x2 = x*x; value_type si; if(x == 0.0) return 0.0; if(x <= 16.0) { value_type xr = x; si = x; for(unsigned int k = 1;k <= 40;++k) { si += (xr *= -0.5*(value_type)(2*k-1)/(value_type)k/(value_type)(4*k*(k+1)+1)*x2); if(std::fabs(xr) < std::fabs(si)*eps) break; } return sgn ? si:-si; } if(x <= 32.0) { unsigned int m = std::floor(47.2+0.82*x); std::vector<double> bj(m+1); value_type xa1 = 0.0f; value_type xa0 = 1.0e-100f; for(unsigned int k=m;k>=1;--k) { value_type xa = 4.0*(value_type)k*xa0/x-xa1; bj[k-1] = xa; xa1 = xa0; xa0 = xa; } value_type xs = bj[0]; for(unsigned int k=3;k <= m;k += 2) xs += 2.0*bj[k-1]; for(unsigned int k=0;k < m;++k) bj[k] /= xs; value_type xr = 1.0; value_type xg1 = bj[0]; for(int k=2;k <= m;++k) xg1 += bj[k-1]*(xr *= 0.25*(2*k-3)*(2*k-3)/((k-1)*(2*k-1)*(2*k-1))*x); xr = 1.0; value_type xg2 = bj[0]; for(int k=2;k <= m;++k) xg2 += bj[k-1]*(xr *= 0.25*(2*k-5)*(2*k-5)/((k-1)*(2*k-3)*(2*k-3))*x); si = x*std::cos(x/2.0)*xg1+2.0*std::sin(x/2.0)*xg2-std::sin(x); return sgn ? si:-si; } value_type xr = 1.0; value_type xf = 1.0; for(unsigned int k=1;k <= 9;++k) xf += (xr *= -2.0*k*(2*k-1)/x2); xr = 1.0/x; value_type xg = xr; for(unsigned int k=1;k <= 8;++k) xg += (xr *= -2.0*(2*k+1)*k/x2); si = 1.570796326794897-xf*std::cos(x)/x-xg*std::sin(x)/x; return sgn ? si:-si; }
void Matrix::test(void) { int i,j; //Matrix *A,*B,*C,*AT,*K; /*test matrix mult*/ // A = new Matrix(3,2); // B = new Matrix(2,3); // C = new Matrix(3,3); // AT = new Matrix(2,3); // K = new Matrix(2*3,3*2); Matrix A(3,2),B(2,3),C(3,3),AT(2,3),K(2*3,3*2); Matrix M(3,3),x(3,1),b(3,1); A[0][0] = 0; A[0][1] = 1; A[1][0] = 3; A[1][1] = 1; A[2][0] = 2; A[2][1] = 0; B[0][0] = 4; B[0][1] = 1; B[0][2] = 0; B[1][0] = 2; B[1][1] = 1; B[1][2] = 2; std::cout << A.mat[1][0] << std::endl; C = Matrix::matrix_mult(A,B); for(i=0;i<3;i++) { for(j=0;j<3;j++) std::cout << C[i][j] << " "; std::cout << std::endl; } std::cout << "now A transposed" << std::endl; A.transpose(AT); for(i=0;i<2;i++) { for(j=0;j<3;j++) std::cout << AT[i][j] << " "; std::cout << std::endl; } std::cout << "now Kronecker product" << std::endl; K = Matrix::kron_(A,B); std::cout << "product calced " << K.getM() << " " << K.getN() << std::endl; for(i=0;i<2*3;i++) { for(j=0;j<3*2;j++) std::cout << K.mat[i][j] << " "; std::cout << std::endl; } cv::Mat_<double> a(3,2), l(2,3); a(0,0) = 0; a(0,1) = 1; a(1,0) = 3; a(1,1) = 1; a(2,0) = 2; a(2,1) = 0; l(0,0) = 4; l(0,1) = 1; l(0,2) = 0; l(1,0) = 2; l(1,1) = 1; l(1,2) = 2; cv::Mat_<double> k = Matrix::kronecker(a,l); std::cout << "mat cv Kronecker" << std::endl << Matrix(k); Matrix sub(3,6); sub = submatrix_(K,2,4); std::cout << "Submatix of K rows 2 to 4 is : \n" << sub; std::cout << "now test solving a linear system using SVD: " << std::endl; std::cout << "A*x = b; A = U*D*V', inv(A) = V*inv(D)*U', x = V*inv(D)*U'*b" << std::endl; //if element in diagonal of D is 0 set element in inv(D) to 0 proof in numerical recipies M[0][0] = 4; M[0][1] = 1.5; M[0][2] = 2; M[1][0] = 3; M[1][1] = 3; M[1][2] = 1; M[2][0] = 2; M[2][1] = 1; M[2][2] = 5; b[0][0] = 10.6; b[1][0] = 11.3; b[2][0] = 9; //x should be 1.5, 2, 0.8 Matrix result = solveLinSysSvd(M,b); std::cout << " The result of the linear system is : " << std::endl; std::cout << result; A = Matrix::matrix_mult(Matrix::eye(2),Matrix::matrix_mult(Matrix::eye(2),Matrix::eye(2))); cv::Mat_<double> aj(2,2); cv::Mat_<double> bj(2,1); aj(0,0) = 2; aj(0,1) = 1; aj(1,0) = 5; aj(1,1) = 7; bj(0,0) = 11; bj(1,0) = 13; cv::Mat_<double> xj(2,1); Matrix::jacobi(aj,bj,xj); std::cout << "jacobi " << Matrix(xj); }