hdu3076----ssworld VS DDD

前端之家收集整理的这篇文章主要介绍了hdu3076----ssworld VS DDD前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

ssworld VS DDD

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


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 3073 3074

此题略坑,第一个值a是第二个人的hp,第二个值b才是第一个人的
令dp[i][j]表示第一个人赢了i次,第二个人赢了j次的概率

当然转移的时候要注意如果(第一个人赢了a次,那么他已经赢了,就不用去转移了,同样第二个人赢了b次,也不用去转移)

/*************************************************************************
    > File Name: hdu3076.cpp
    > Author: ALex
    > Mail: 405045132@qq.com 
    > Created Time: 2014年12月22日 星期一 10时35分19秒
 ************************************************************************/

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 2005;

double dp[N][N];
double x[10],y[10];

int main()
{
	int a,b;
	double p1,p2,p3;
	while (~scanf("%d%d",&a,&b))
	{
		p1 = p2 = p3 = 0;
		for (int i = 0; i < 6; ++i)
		{
			scanf("%lf",&x[i]);
		}
		for (int i = 0; i < 6; ++i)
		{
			scanf("%lf",&y[i]);
		}
		for (int i = 0; i < 6; ++i)
		{
			for (int j = 0; j < i; ++j)
			{
				p1 += x[i] * y[j];
			}
		}
		for (int i = 0; i < 6; ++i)
		{
			for (int j = 0; j < i; ++j)
			{
				p2 += y[i] * x[j];
			}
		}
		p3 = 1.0 - p1 - p2;
		p1 /= (1.0 - p3);
		p2 /= (1.0 - p3);
		memset (dp,sizeof(dp));
		dp[0][0] = 1.0;
//		printf("%f %f %f\n",p1,p3);
		for (int i = 0; i <= a; ++i)
		{
			for (int j = 0; j <= b; ++j)
			{
				if (j < b && i > 0)
				{
					dp[i][j] += p1 * dp[i - 1][j];
				}
				if (i < a && j > 0)
				{
					dp[i][j] += p2 * dp[i][j - 1];
				}
			}
		}
		double ans = 0;
		for (int i = 0; i < b; ++i)
		{
			ans += dp[a][i];
		}
		printf("%lf\n",ans);
	}
	return 0;
}
原文链接:https://www.f2er.com/javaschema/285083.html

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