ssworld VS DDD

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 1487    Accepted Submission(s): 304

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
2009 Multi-University Training Contest 17 - Host by NUDT

求概率。和求期望的方法同样,只是不用再+1,dp[i][j]表示a有i血量,b有j血量时a赢的概率,由于要求a赢的概率。所以在dp[i][0]a赢得概率是1,dp[0][j]时a赢的概率是0。

一个坑点。血量是倒着输入的。

。。。坑了一天。。。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int hp1 , hp2 ;
double dp[2][2100] ;
double a , b , p ;
double ka[10] , kb[10] ;
int main()
{
int i , j , flag ;
while(scanf("%d %d", &hp2, &hp1)!=EOF)
{
for(i = 1 ; i <= 6 ; i++)
scanf("%lf", &ka[i]);
for(j = 1 ; j <= 6 ; j++)
scanf("%lf", &kb[j]);
memset(dp,0,sizeof(dp));
a = b = p = 0.0 ;
for(i = 1 ; i <= 6 ; i++)
for(j = 1 ; j <= 6 ; j++)
{
if(i > j)
a += ka[i]*kb[j] ;
else if( i < j )
b += ka[i]*kb[j] ;
else
p += ka[i]*kb[j] ;
}
dp[0][0] = dp[1][0] = 1.0 ;
flag = 0 ;
for(i = 1 ; i <= hp1 ; i++)
{
flag = 1 - flag ;
for(j = 0 ; j <= hp2 ; j++)
{
if( j == 0 ) continue ;
dp[flag][j] = ( a*dp[flag][j-1] + b*dp[1-flag][j] ) / (1.0-p) ;
}
}
printf("%.6lf\n", dp[flag][hp2]);
}
return 0;
}

最新文章

  1. STM32 复合设备编写
  2. Lua小技巧
  3. cocos2d-x之文件读写
  4. (1)定义一个接口CanFly,描述会飞的方法public void fly(); (2)分别定义类飞机和鸟,实现CanFly接口。 (3)定义一个测试类,测试飞机和鸟,在main方法中创建飞机对象和鸟对象, 再定义一个makeFly()方法,其中让会飞的事物飞。并在main方法中调用该方法, 让飞机和鸟起飞。
  5. java源程序---可执行文件(.exe)----安装包
  6. Computer assembly and maintenance
  7. JavaScript正则详谈
  8. 【XJOI-NOIP16提高模拟训练9】题解。
  9. spring boot + neo4j restful
  10. Javascript中的Microtask和Macrotask——从一道很少有人能答对的题目说起
  11. Hessian源码分析--总体架构
  12. 前端-JavaScript2-5——JavaScript之运算符进阶
  13. confidence interval
  14. for循环以及数据类型
  15. 《深入分析Java Web技术内幕》读书笔记 - 第1章 深入Web请求过程
  16. dockerfile创建php容器(安装memcached、redis、gd、xdebug扩展)
  17. Jquery停止动画
  18. SpringBoot与SpringCloud学习指南
  19. apache中配置php支持模块模式、cgi模式和fastcgi模式
  20. HNU Joke with permutation (深搜dfs)

热门文章

  1. vue 中父子组件传值:props和$emit
  2. CSS Modules使用方法
  3. VIJOS【1234】口袋的天空
  4. Java中Collections的sort方法和Comparable与Comparator的比较
  5. .net显示今天农历的代码!
  6. ARM QT实现多点触摸【转】
  7. uva 1149:Bin Packing(贪心)
  8. Codeforces Round #451 (Div. 2) B. Proper Nutrition【枚举/扩展欧几里得/给你n问有没有两个非负整数x,y满足x&#183;a + y&#183;b = n】
  9. 2016北京集训测试赛(八)Problem C: 直径
  10. Jackson是线程安全的吗