标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 707 Accepted Submission(s): 285
#include <cstdio> #include <cstring> double a[4][4][1100], p[4][4]; void deal() { memset(a, 0.0, sizeof(a)); for(int i=1; i<=3; i++) for(int j=1; j<=3; j++) a[i][j][1]=p[i][j]; for(int i=2; i<=1001; i++) for(int j=1; j<=3; j++) for(int k=1; k<=3; k++) for(int l=1; l<=3; l++) a[j][k][i] += a[j][l][i-1]*p[l][k]; //例如: 0--> 3: 0-->0-->3,0-->1-->3, 0-->2-->3; } int main() { int m; scanf("%d", &m); while(m--) { for(int i=1; i<=3; i++) for(int j=1; j<=3; j++) scanf("%lf", &p[i][j]); deal(); int n; scanf("%d", &n); while(n--) { int x, y, z; scanf("%d%d%d", &x, &y, &z); printf("%.3lf\n", a[x][y][z]); } } return 0; }
上述deal() ;
#include <stdio.h> #define N 1010 int main() { double p[4][4], f[1010][3]; int Q; scanf("%d", &Q); while(Q--) { scanf ("%lf %lf %lf %lf %lf %lf %lf %lf %lf",&p[1][1],&p[1][2],&p[1][3],&p[2][1],&p[2][2],&p[2][3],&p[3][1],&p[3][2],&p[3][3]); int t; scanf("%d", &t); while(t--) { int a, b, c; scanf("%d %d %d", &a, &b, &c); f[1][0] = p[a][1]; f[1][1] = p[a][2]; f[1][2] = p[a][3]; for(int i=2; i<=c; i++) { f[i][0] = f[i-1][0] * p[1][1] + f[i-1][1] * p[2][1] + f[i-1][2]*p[3][1] ; f[i][1] = f[i-1][0] * p[1][2] + f[i-1][1] * p[2][2] + f[i-1][2]*p[3][2] ; f[i][2] = f[i-1][0] * p[1][3] + f[i-1][1] * p[2][3] + f[i-1][2]*p[3][3] ; } printf("%.3lf\n", f[c][b-1]); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/fengshun/p/5348448.html