ssworld VS DDD
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2637 Accepted Submission(s): 526
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
Recommend
lcy
题意:两个人玩游戏,他们的血量分别是HP1,HP2,他们掷骰子,点数小的一方会扣一滴血,相同则都不扣血,给出两个人掷出1-6的概率,问第一个赢的概率是多少。
思路:首先根据两个人掷点的概率可以求出在一次掷点中第一个人赢的概率P1,第二个人赢的概率P2,平局的概率P3,P3对结果没有影响,可以忽略。通过概率dp将一次掷点推广到多次掷点上,建立递推关系DP【i】【j】表示第一个赢i次,第二个人赢j次的概率是多少 那么结果就是对第一个人赢HP2-1次,第二个人赢0到HP1-1次的概率求和*P1。
Hint:OJ后台数据有误,输入的时候把两个人的血量互换才可AC
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
#define ms(a,b)memset(a,b,sizeof(a))
#define eps 1e-10
#define inf 1e8
double dp[2005];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
memset(dp,0,sizeof(dp));
double x[7],y[7];
// cout<<n<<" "<<m<<endl;
for(int i=1;i<=6;i++)
scanf("%lf",&x[i]);
for(int i=1;i<=6;i++)
scanf("%lf",&y[i]);
double p0,p1;
p0=p1=0;
for(int i=1;i<=6;i++)
{
double sum=0;
for(int j=1;j<i;j++)
{
sum+=y[j];
}
p0+=sum*x[i];
}
for(int i=1;i<=6;i++)
{
double sum=0;
for(int j=1;j<i;j++)
{
sum+=x[j];
}
p1+=sum*y[i];
}
double pp=p0+p1;
if(pp==0)
{
p0=p1=0;
}
else {
p0=p0/pp;
p1=p1/pp;
}
//cout<<p0<<" "<<p1<<endl;
dp[0]=1.0;
double ans=0;
for(int i=0;i<n;i++)
{
for(int j=1;j<m;j++)
{
dp[j]+=dp[j-1]*p1;
if(i==n-1) ans+=dp[j]*p0;
}
if(i==n-1) ans+=dp[0]*p0;
for(int j=0;j<m;j++)
{
dp[j]*=p0;
}
}
printf("%.6lf\n",ans);
}
return 0 ;
}