标签:ack stdio.h important pac out center stand 16px rpg
InputThe first line of the input contains an integer t?C determining the number of datasets. Then t lines follows. Each line contains 6 numbers pi, i ∈{ 1, 2, …, 6 }, indicating the probability of getting 1 to 6 after you toss the die every time . p1+ p2+ … + p6 = 1.
OutputFor each test case, output the probability of touching each important grid. accurate up to 1 decimal places. There is a blank line between test cases. See the Sample Output to get the exactly output format.
Sample Input
2
0.000 1.000 0.000 0.000 0.000 0.000
0.500 0.000 0.000 0.000 0.000 0.500
Sample Output
5: 0.0%
12: 100.0%
22: 0.0%
29: 0.0%
33: 0.0%
38: 0.0%
42: 0.0%
46: 0.0%
50: 0.0%
55: 0.0%
5: 3.1%
12: 30.5%
22: 27.3%
29: 24.6%
33: 21.9%
38: 10.9%
42: 0.8%
46: 0.0%
50: 4.4%
55: 1.0%
//题意:第一行测试组数 T ,然后给出掷骰子出现 1 2 3 4 5 6 的概率,问到达指定位置的概率是多少?
简单概率dp
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 using namespace std; 5 6 double dp[20][100]; // i 次到 j 的概率 7 double p[10]; 8 double a[10]; 9 10 int main() 11 { 12 int T; 13 cin>>T; 14 while (T--) 15 { 16 for (int i=1;i<=6;i++) 17 scanf("%lf",&p[i]); 18 memset(dp,0,sizeof(dp)); 19 memset(a,0,sizeof(a)); 20 for (int i=1;i<=6;i++) dp[1][i]=p[i]; 21 for (int i=2;i<=10;i++) 22 { 23 for (int j=0;j<=60;j++) 24 { 25 for (int k=1;k<=6;k++) 26 if (j-k>=0) 27 dp[i][j]+=dp[i-1][j-k]*p[k]; 28 } 29 } 30 for(int i=10;i>0;i--) a[0]+=dp[i][5]; printf("5: %.1lf%%\n",a[0]*100); 31 for(int i=10;i>0;i--) a[1]+=dp[i][12]; printf("12: %.1lf%%\n",a[1]*100); 32 for(int i=10;i>0;i--) a[2]+=dp[i][22]; printf("22: %.1lf%%\n",a[2]*100); 33 for(int i=10;i>0;i--) a[3]+=dp[i][29]; printf("29: %.1lf%%\n",a[3]*100); 34 for(int i=10;i>0;i--) a[4]+=dp[i][33]; printf("33: %.1lf%%\n",a[4]*100); 35 for(int i=10;i>0;i--) a[5]+=dp[i][38]; printf("38: %.1lf%%\n",a[5]*100); 36 for(int i=10;i>0;i--) a[6]+=dp[i][42]; printf("42: %.1lf%%\n",a[6]*100); 37 for(int i=10;i>0;i--) a[7]+=dp[i][46]; printf("46: %.1lf%%\n",a[7]*100); 38 for(int i=10;i>0;i--) a[8]+=dp[i][50]; printf("50: %.1lf%%\n",a[8]*100); 39 for(int i=10;i>0;i--) a[9]+=dp[i][55]; printf("55: %.1lf%%\n",a[9]*100); 40 if (T) cout<<endl; 41 } 42 return 0; 43 }
标签:ack stdio.h important pac out center stand 16px rpg
原文地址:http://www.cnblogs.com/haoabcd2010/p/6748255.html