poj 2151

实在没有发现这个题和二分查找或hash有啥关系....

 1 #include <iostream>
 2 #include <string>
 3 #include <vector>
 4 #include <cstdlib>
 5 #include <cmath>
 6 #include <map>
 7 #include <algorithm>
 8 #include <list>
 9 #include <ctime>
10 #include <set>
11 #include <string.h>
12 #include <queue>
13 #include <cstdio>
14 using namespace std;
15 #define CLR(arr, what) memset(arr, what, sizeof(arr))
16 double pro[1002][32];
17 double dp[1002][32];
18 int main() {
19     int M, T, N;
20 
21     scanf("%d%d%d", &M, &T, &N);
22     while (M || T || N) {
23         CLR(pro, 0);
24         CLR(dp, 0);
25         for (int i = 0; i < T; i++) {
26             for (int j = 0; j < M; j++) {
27                 scanf("%lf", &pro[i][j]);
28             }
29         }
30         for (int i = 0; i < T; i++) {
31             dp[i][0] = 1 - pro[i][0];
32             dp[i][1] = pro[i][0];
33             for (int j = 1; j < M; j++) {
34                 for (int k = j + 1; k >= 0; k--) {
35                     switch (k) {
36                     case 0:
37                         dp[i][k] = dp[i][k] * (1 - pro[i][j]);
38                         break;
39                     default:
40                         dp[i][k] = dp[i][k] * (1 - pro[i][j])
41                                 + dp[i][k - 1] * (pro[i][j]);
42                         break;
43                     }
44                 }
45             }
46         }
47         double p1, p2;
48         p1 = 1;
49         p2 = 1;
50         for (int i = 0; i < T; i++) {
51             double t1, t2;
52             t1 = 0;
53             t2 = 0;
54             for (int j = 1; j < N; j++) {
55                 t1 = t1 + dp[i][j];
56             }
57             t2=1-dp[i][0];
58              p1 = p1 * t1;
59             p2 = p2 * t2;
60         }
61         printf("%.3lf\n", p2 - p1);
62         scanf("%d%d%d", &M, &T, &N);
63     }
64     return 0;
65 }

 

from kakamilan

posted on 2013-05-30 20:52  kakamilan  阅读(141)  评论(0编辑  收藏  举报

导航