HDOJ 题目3076 ssworld VS DDD(概率dp)

前端之家收集整理的这篇文章主要介绍了HDOJ 题目3076 ssworld VS DDD(概率dp)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

ssworld VS DDD

Time Limit: 4000/2000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1607Accepted Submission(s): 330


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.


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.

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|We have carefully selected several similar problems for you: 3069 3070 3071 3072 3073
题目大意:两个人掷筛子,每个人都有血量h1,h2,也有掷6个数的概率,掷一次,点小的血量减一,最后谁的血量先变为0,就输了,求第一个人赢的概率,
ps:这个题的数据有坑,,,,开始一直wa,看了讨论组才知道,,数据反了,,正常应该是输入 h1,h2的,,换了一下顺序就过了。。坑啊
ac代码
#include<stdio.h>
#include<string.h>
double a[10],b[10],dp[2005][2005];
int main()
{
	int h1,h2;
	while(scanf("%d%d",&h2,&h1)!=EOF)
	{
		int i,j;
		double p1,p2,p,w1,w2;
		for(i=1;i<=6;i++)
			scanf("%lf",&a[i]);
		for(i=1;i<=6;i++)
			scanf("%lf",&b[i]);
		p1=p2=0;
		for(i=2;i<=6;i++)
		{
			for(j=1;j<i;j++)
			{
				p1+=a[i]*b[j];
				p2+=a[j]*b[i];
			}
		}
		p=1-p2-p1;
		if(p==1)
			w1=w2=0;
		else
		{
			w1=p1/(1-p);
			w2=p2/(1-p);
		}
		memset(dp,sizeof(dp));
		dp[0][0]=1;
		for(i=0;i<h2;i++)
		{
			for(j=0;j<=h1;j++)
			{
				if(i)
					dp[i][j]+=dp[i-1][j]*w1;
				if(j)
					dp[i][j]+=dp[i][j-1]*w2;
			}
		}
		double ans=0;
		for(i=0;i<h1;i++)
		{
			ans+=dp[h2-1][i]*w1;
		}
		printf("%.6lf\n",ans);
	}
}

猜你在找的设计模式相关文章