Weather conditions
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 707 Accepted Submission (s): 285
Problem description If we divide the weather into rainy days, cloudy and sunny 3 kinds, the probability of conversion between a given variety of weather, such as rainy day conversion to rainy days, cloudy and sunny the probability of 0.4,0.3,0.3 respectively. Then, on rainy days, there is rain, The probability of cloudy and sunny Days is 0.4,0.3,0.3. Now give you today's weather conditions, ask you n a day after the occurrence of some weather probability.
Input we assume here that the PIJ represents 3 different weather conditions, and the probability of the change from I weather to J weather.
First, a number T represents the number of groups of data.
Each set of data starts with 9 numbers, p11,p12,p13,......, p32,p33, and the next line is a number m, which indicates the number of questions. Each question has 3 data, i,j,n, expressed over n days from I weather conditions to J weather conditions (1<=i,j<=3 1<=n<=1000).
Output corresponds to the probability of each question being raised (3 decimal places are reserved).
Sample Input10.4 0.3 0.3 0.2 0.5 0.3 0.1 0.3 0.631 1 12 3 11 1 2
Sample Output0.4000.3000.250hint: If the GC submission is unsuccessful, you can change the VC to try
Authorxhd
Source ACM Summer Training Team Practice Competition (IV)
Recommendlcy | We have carefully selected several similar problems for you:1757 3117 1427 3483 3519
#include <cstdio>#include<cstring>Doublea[4][4][1100], p[4][4];voiddeal () {memset (a),0.0,sizeof(a)); for(intI=1; i<=3; i++) for(intj=1; j<=3; J + +) a[i][j][1]=P[i][j]; for(intI=2; i<=1001; i++) for(intj=1; j<=3; J + +) for(intk=1; k<=3; k++) for(intL=1; l<=3; l++) A[j][k][i]+ = a[j][l][i-1]*P[L][K];//Example: 0--> 3:0-->0-->3,0-->1-->3, 0-->2-->3; }intMain () {intM scanf"%d", &m); while(m--) { for(intI=1; i<=3; i++) for(intj=1; j<=3; J + +) scanf ("%LF", &P[i][j]); Deal (); intN scanf"%d", &N); while(n--) { intx, y, Z; scanf ("%d%d%d", &x, &y, &z); printf ("%.3lf\n", A[x][y][z]); } } return 0;}
The above deal ();
#include <stdio.h>#defineN 1010intMain () {Doublep[4][4], f[1010][3]; intQ; 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]); intT scanf"%d", &t); while(t--) { intA, 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(intI=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;}
hdoj1437--weather conditions