题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3076
Problem Description
One day,sssworld and DDD play games together,but there are some special rules in this games.
They both have their own HP. Each round they dice respectively and get the points P1 and P2 (1 <= P1,P2 <= 6). Small number who,whose HP to reduce 1,the same points will remain unchanged. If one of them becomes 0 HP,he loses.
As a result of technical differences between the two,each person has different probability of throwing 1,2,3,4,5,6. So we Couldn’t predict who the final winner.
They both have their own HP. Each round they dice respectively and get the points P1 and P2 (1 <= P1,P2 <= 6). Small number who,whose HP to reduce 1,the same points will remain unchanged. If one of them becomes 0 HP,he loses.
As a result of technical differences between the two,each person has different probability of throwing 1,2,3,4,5,6. So we Couldn’t predict who the final winner.
Input
There are multiple test cases.
For each case,the first line are two integer HP1,HP2 (1 <= HP1,HP2 <= 2000),said the first player sssworld’s HP and the second player DDD’s HP.
The next two lines each have six floating-point numbers per line. The jth number on the ith line means the the probability of the ith player gets point j. The input data ensures that the game always has an end.
For each case,the first line are two integer HP1,HP2 (1 <= HP1,HP2 <= 2000),said the first player sssworld’s HP and the second player DDD’s HP.
The next two lines each have six floating-point numbers per line. The jth number on the ith line means the the probability of the ith player gets point j. The input data ensures that the game always has an end.
Output
One float with six digits after point,indicate the probability sssworld won the game.
Sample Input
5 5 1.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 1.000 5 5 0.000 0.000 0.000 0.000 0.000 1.000 1.000 0.000 0.000 0.000 0.000 0.000
Sample Output
0.000000 1.000000
Source
题意:
有A、B个人分别有H1 H2的血量,他们轮流的扔骰子,扔的点数小的减一血,
若扔的点数一样则都不变,谁先到减0, 谁输,问A赢的概率。
代码如下:
#include <cstdio> #include <cstring> double dp[2017][2017]; //dp[i][j]表示A胜j次,B胜i次的概率。 int main() { int n,m; double a[7],b[7]; while(~scanf("%d%d",&m,&n)) { memset(dp,sizeof(dp)); double p1 = 0,p2 = 0,p = 0; //设p1,p2,p表示A赢,B赢,两者平局。 for(int i = 1; i <= 6; i++) { scanf("%lf",&a[i]); } for(int i = 1; i <= 6; i++) { scanf("%lf",&b[i]); } for(int i = 2; i <= 6; i++)//A赢 { for(int j = 1; j < i; j++) { p1+=a[i]*b[j]; } } for(int j = 2; j <= 6; j++)//B赢 { for(int i = 1; i < j; i++) { p2+=a[i]*b[j]; } } double w1,w2; //w1,w2表示整个过程之中赢一局的概率 p = 1-p1-p2; if(p == 1) { w1 = 0; w2 = 0; } else { w1 = p1/(1-p); w2 = p2/(1-p); } dp[0][0] = 1; for(int j = 0; j < m; j++) { for(int i = 0; i <= n; i++) { if(j > 0) dp[i][j]+=dp[i][j-1]*w1; if(i > 0) dp[i][j]+=dp[i-1][j]*w2; } } double maxx = 0; for(int i = 0; i < n; i++) { maxx+=dp[i][m-1]*w1; } printf("%.6lf\n",maxx); } return 0; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。