http://acm.split.hdu.edu.cn/showproblem.php?pid=3076

ssworld VS DDD

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

题意:两个人玩游戏,给出各自掷骰子得到不同点数的概率,点数小的扣一血,相同不扣血。

思路:概率DP,处理到第二个人血量剩余1的时候,然后再处理他降到0的时候的情况,不能直接循环第二个人血量为0的情况,即ans += dp[i][0] (1 <= i <= h1),因为这样的话dp[i][0]继承了dp[i+1][0]的状态,但是为0的时候游戏已经停止了,这样是不合理的。应该是ans += dp[i][1] * win / (1 - ave),这样的话才不会错,要注意考虑(1-ave)的情况,因为当前回合如果平局的话,下一个回合还是有机会赢的。(PS:很感谢ZLW师兄帮我debug了这题好久233)

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
const double eps = 0.00000001;
double d[][];
double dp[][]; int main()
{
int h1, h2;
while(~scanf("%d%d", &h2, &h1)) { //题目输入反了
double win = , lose = , ave = ;
for(int i = ; i < ; i++)
for(int j = ; j < ; j++)
scanf("%lf", &d[i][j]);
for(int i = ; i < ; i++) {
for(int j = ; j < ; j++) {
if(i == j) ave += d[][i] * d[][j];
else if(i < j) lose += d[][i] * d[][j];
else win += d[][i] * d[][j];
}
}
// printf("SIZE : %d\n", sizeof(dp));
double ans = ;
if(eps >= fabs( - ave)) {
printf("%.6f\n", ans);
continue;
}
for(int i = ; i <= h1+; i++)
for(int j = ; j <= h2+; j++)
dp[i][j] = ;
// dp[h1+1][h2-1] = dp[h1-1][h2+1] = dp[h1+1][h2] = dp[h1][h2+1] = 0;
dp[h1][h2] = ;
for(int i = h1; i >= ; i--) {
for(int j = h2; j >= ; j--) {
if(i == h1 && j == h2) continue;
dp[i][j] = (dp[i+][j] * lose + dp[i][j+] * win) / ((double) - ave);
}
}
for(int i = ; i <= h1; i++)
ans += dp[i][] * win / ((double) - ave);
printf("%.6f\n", ans);
}
return ;
}

HDU 3076:ssworld VS DDD(概率DP)的更多相关文章

  1. hdu 3076 ssworld VS DDD (概率dp)

    ///题意: /// A,B掷骰子,对于每一次点数大者胜,平为和,A先胜了m次A赢,B先胜了n次B赢. ///p1表示a赢,p2表示b赢,p=1-p1-p2表示平局 ///a赢得概率 比一次p1 两次 ...

  2. HDU 3076 ssworld VS DDD 概率dp,无穷级数,oj错误题目 难度:2

    http://acm.hdu.edu.cn/showproblem.php?pid=3076 不可思议的题目,总之血量越少胜率越高,所以读取时把两人的血量交换一下 明显每一轮的胜率和负率都是固定的,所 ...

  3. hdu3076--ssworld VS DDD(概率dp第三弹,求概率)

    ssworld VS DDD Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  4. hdu3076ssworld VS DDD 概率dp

    //ssworld VS DDD 两个人有血量值 hp1 , hp2  //两人掷骰子得到每一点的概率已知 //ssword赢的概率 //dp[i][j]  表示有第一个人血量为i.第二个人的血量为j ...

  5. HDU 5781 ATM Mechine (概率DP)

    ATM Mechine 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5781 Description Alice is going to take ...

  6. HDU 4050 wolf5x(动态规划-概率DP)

    wolf5x Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  7. hdu 4405 Aeroplane chess (概率DP)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. HDU 4336——Card Collector——————【概率dp】

    Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  9. HDU 3853:LOOPS(概率DP)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Problem Description   Akemi Homura is a M ...

  10. HDU 4865 Peter's Hobby --概率DP

    题意:第i天的天气会一定概率地影响第i+1天的天气,也会一定概率地影响这一天的湿度.概率在表中给出.给出n天的湿度,推测概率最大的这n天的天气. 分析:这是引自机器学习中隐马尔科夫模型的入门模型,其实 ...

随机推荐

  1. linux内核编译相关

    参考:http://www.arm.linux.org.uk/docs/kerncomp.php 一. 内核编译1) linux 2.4make clean/make mrpropermake dep ...

  2. 注意SQLServer2012中带参数的XP_ReadErrorLog

    --15:26 2014-6-10数据库错误日志通知其中有一部分是检测ERRORLOG中若有用户登录失败信息时,会记录到Errorlog表,并邮件提醒.当时直接从同事那拿过来的脚本(08),按理说版本 ...

  3. 不等高cell的搭建(一)

    一.界面搭建   1.确定开发模式      如果界面是固定的,可以用xib      界面的一些内容不固定,就用纯代码      cell用什么方式去开发(我们采用纯代码和xib结合的方式)   2 ...

  4. Cocoapods注意点

    1 安装和升级$ sudo gem install cocoapods $ pod setup 2 更换为taobao的源 $ gem sources -r https://rubygems.org/ ...

  5. @Transactional

    转载请标明出处:http://blog.csdn.net/cuker919/archive/2010/10/21/5957209.aspx Spring事务的传播行为 在service类前加上@Tra ...

  6. [原创]java WEB学习笔记73:Struts2 学习之路-- strut2中防止表单重复提交

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  7. [原创]java WEB学习笔记70:Struts2 学习之路-- struts2拦截器源码分析,运行流程

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  8. Ruby On Rails 在线学习好网站

    最好学习Ruby网站: https://ruby-china.org/    我的用户名:19920625lsg,  密码为最常用的 Ruby on Rails 教程 http://railstuto ...

  9. C++之路起航——标准模板库(deque)

    deque(双端队列):http://baike.baidu.com/link?url=JTvA2cuLubptctHZwFxswvlZvxNdFOxmifsYCGLj5IZF-Tj4rbWLv8Jn ...

  10. paper 32 :svm参数优化的进展

    从今天开始,我的微信公众号“天空之窗”就暂且停止更新内容了,专心搞研究!上午从师姐那儿淘到一份关于faruto讲解的Libsvm-FarutoUltimate3.1 based on libsvm-3 ...