您的位置:首页 > 其它

矩阵模版(例题3070、3744)

2012-05-30 21:36 225 查看
struct matrix
{
double A[NMax][NMax];
matrix operator*(const matrix & m)
{
matrix ret={0,0,0,0};
for(int i=0;i<NMax;i++)
for(int k=0;k<NMax;k++)
if(A[i][k]>0.0)
for(int j=0;j<NMax;j++)
ret.A[i][j]+=A[i][k]*m.A[k][j];
return ret;
}
}def={1,0,0,1};
matrix pow(matrix a,int n)
{
matrix tmp=a,ret=def;
while(n!=0)
{
if((n&1)!=0) ret=ret*tmp;
tmp=tmp*tmp;
n>>=1;
}
return ret;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: