Example #1
0
File: 1002.cpp Project: ACLB/ACM
Matrix Pow(LL m) {
    Matrix ans ; ans.Clear();
    ans.n = 1; ans.m = 2;
    ans.a[0][0] = ans.a[1][0] = 1;
    Matrix s ; s.Clear();
    s.n = s.m = 2;
    s.a[0][0] = s.a[0][1] = 1;
    s.a[1][0] =2; s.a[1][1] = 1;

    while(m) {
        if(m&1) ans = s*ans;

        s = s*s;
        m>>=1;
    }
    return ans;
}
Example #2
0
File: 1002.cpp Project: ACLB/ACM
    Matrix  operator * (const Matrix  & b) const {
        Matrix temp; temp.Clear();

        temp.n = n; temp.m = b.m;
        for(int i = 0;i<n;i++) {
            for(int j = 0 ;j<b.m;j++) {
                for(int k = 0 ;k<m;k++) {
                    temp.a[i][j] = (temp.a[i][j] + (a[i][k] * b.a[k][j])%Mod)%Mod;
                }
            }
        }
        return temp;
    }
Example #3
0
Matrix Pow(Matrix m1,LL b)
{
    Matrix ans;ans.Clear();
    for(int i=0;i<2;i++)
        ans.mat[i][i]=1;
    while(b)
    {
        if(b&1)
           ans=mult(ans,m1);
        b>>=1;
        m1=mult(m1,m1);
    }
    return ans;
}
Example #4
0
SDOut SDMax (SDIn& si) {

    SDOut so;

    Matrix<double>& posh = si.posh;
    Matrix<double>& sh   = si.sh;

    PolyVal<double>& pkx = *(si.pkx);
    PolyVal<double>& pky = *(si.pky);
    PolyVal<double>& pkz = *(si.pkz);

    size_t ssp = size(posh,0);
    size_t sss = size(sh  ,0);

    Matrix<double>  dpp (ssp,1);
    Matrix<double>  dsp (sss,1);
    Matrix<double>  csp (ssp,3);

    for (size_t i = 0; i < ssp-1; i++)
        dpp[i] = posh[i+1] - posh[i];
    dpp[ssp-1] = dpp[ssp-2];

    for (size_t i = 0; i < sss-1; i++)
        dsp[i] = sh[i+1] - sh[i];
    dsp[ssp-1] = dsp[ssp-2];

    printf (".");
    fflush (stdout);

    for (size_t i = 1; i < ssp-1; i++) {
        csp(i,0) = (pkx.Lookup (posh[i] + dpp[i]) - pkx.Lookup (posh[i])) / dsp[i];
        csp(i,1) = (pky.Lookup (posh[i] + dpp[i]) - pky.Lookup (posh[i])) / dsp[i];
        csp(i,2) = (pkz.Lookup (posh[i] + dpp[i]) - pkz.Lookup (posh[i])) / dsp[i];
    }

    printf (".");
    fflush (stdout);

    dpp.Clear();

    Matrix<double>  dpm (ssp,1);
    Matrix<double>  dsm (sss,1);
    Matrix<double>  csm (ssp,3);

    for (size_t i = 1; i < ssp;   i++)
        dpm[i] = posh[i] - posh[i-1];
    dpm[0] = dpm[1];

    for (size_t i = 1; i < sss;   i++)
        dsm[i] = sh[i] - sh[i-1];
    dsm[0] = dsm[1];

    for (size_t i = 1; i < ssp-1; i++) {
        csm(i,0) = (pkx.Lookup (posh[i]) - pkx.Lookup (posh[i] - dpm[i])) / dsm[i];
        csm(i,1) = (pky.Lookup (posh[i]) - pky.Lookup (posh[i] - dpm[i])) / dsm[i];
        csm(i,2) = (pkz.Lookup (posh[i]) - pkz.Lookup (posh[i] - dpm[i])) / dsm[i];
    }

    dpm.Clear();

    Matrix<double>  css (ssp,3);

    for (size_t i = 1; i < ssp-1; i++) {
        css(i,0) = (csp(i,0) - csm(i,0)) / ((dsm[i] + dsp[i]) * 0.5);
        css(i,1) = (csp(i,1) - csm(i,1)) / ((dsm[i] + dsp[i]) * 0.5);
        css(i,2) = (csp(i,2) - csm(i,2)) / ((dsm[i] + dsp[i]) * 0.5);
    }

    csp.Clear();
    csm.Clear();
    dsp.Clear();
    dsm.Clear();

    printf (". ");
    fflush (stdout);

    so.k   = Matrix<double> (ssp,1);
    so.phi = Matrix<double> (ssp,1);

    for (size_t i = 1; i < ssp-1; i++)
        so.k[i]  = sqrt (pow(css(i,0),2) + pow(css(i,1),2) + pow(css(i,2),2));

    so.k[0]     = so.k[1];
    so.k[sss-1] = so.k[sss-2];

    css.Clear();

    double mgr = GAMMA / 10.0 * si.mgr;
    double msr = GAMMA / 10.0 * si.msr;

    for (size_t i = 0; i < ssp; i++)
        so.phi[i] = MIN (mgr, sqrt(msr/so.k[i]));

    return so;

}