#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
struct M
{
int n;
double m[3][3];
M(int nn=3)
{
n = nn;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
m[i][j]=0.0L;
}
};
M orignal;
M mul(M a,M b)
{
M c(a.n);
for(int i=0;i<a.n;i++)
for(int j=0;j<a.n;j++)
for(int k=0;k<a.n;k++)
c.m[i][j] += a.m[i][k]*b.m[k][j];
return c;
}
M quick(int k)
{
if(k==1) return orignal;
if(k==2) return mul(orignal,orignal);
M temp = quick(k/2);
if(k%2)
return mul(temp,mul(temp,orignal));
else return mul(temp,temp);
return orignal;
}
void init()
{
int test;
cin>>test;
while (test--)
{
for(int i=0;i<3;i++ )
for(int j=0;j<3;j++)
cin>>orignal.m[i][j];
int p;
cin>>p;
int x,y,z;
while(p--)
{
cin>>x>>y>>z;
M en=quick(z);
printf("%.3lf\n",en.m[x-1][y-1]);
}
}
}
int main()
{
init();
return 0;
}
天气情况
最新推荐文章于 2024-08-03 15:50:23 发布
