首页 > 代码库 > BZOJ2318 Spoj4060 game with probability Problem
BZOJ2318 Spoj4060 game with probability Problem
这题嘛。。。不会
Orz 这个解答 P33开始 2333
1 /************************************************************** 2 Problem: 2318 3 User: rausen 4 Language: C++ 5 Result: Accepted 6 Time:0 ms 7 Memory:808 kb 8 ****************************************************************/ 9 10 #include <cstdio>11 #include <cmath>12 #include <algorithm>13 14 using namespace std;15 typedef double lf;16 const int N = 105;17 int T, n;18 lf p, q, k;19 lf p1, p2, p3, p4;20 lf p5, p6, p7, p8;21 lf f[N], s[N];22 23 int main(){24 scanf("%d", &T);25 int i;26 while (T--){27 scanf("%d%lf%lf", &n, &p, &q);28 f[0] = 0, s[0] = 1;29 n = min(100, n);30 k = 1 - (1 - p) * (1 - q);31 p1 = p / k, p2 = (1 - p) * q / k;32 p3 = (1 - q) * p / k, p4 = q / k;33 k = 1 - p * q;34 p5 = (1 - p) / k, p6 = (1 - q) * p / k;35 p7 = q * (1 - p) / k, p8 = (1 - q) / k;36 for (i = 1; i <= n; ++i)37 if (f[i - 1] < s[i - 1]){38 f[i] = p1 * s[i - 1] + p2 * f[i - 1];39 s[i] = p3 * s[i - 1] + p4 * f[i - 1];40 } else{41 f[i] = p5 * s[i - 1] + p6 * f[i - 1];42 s[i] = p7 * s[i - 1] + p8 * f[i - 1];43 }44 printf("%.6lf\n", f[n]);45 }46 return 0;47 }
BZOJ2318 Spoj4060 game with probability Problem
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。