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. 第四篇 SQL Server代理配置数据库邮件

    本篇文章是SQL Server代理系列的第四篇,详细内容请参考原文. 正如这一系列的前几篇所述,SQL Server代理作业是由一系列的作业步骤组成,每个步骤由一个独立的类型去执行.SQL Serve ...

  2. Tigase Server Clustering

    首先,在服务器上启用集群 修改init.properties --cluster-mode=true 自定义端口 允许自定义,但是所有的实例都要使用相同的端口,以便通讯 --cl-comp-ports ...

  3. jquery文字溢出处理,超出变省略号

    //文字溢出 $(function(){ $(".d_dt a").each(function(){ var maxwidth =100; if($(this).text().le ...

  4. poj1703 Find them, Catch them 并查集

    poj(1703) Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26992   ...

  5. C#: enum

    C#的枚举类型跟C++差不多,一般我们将enum设为单个状态,比如enum color_t { RED, BLACK, GREEN}, 只能选择一个 而有的时候枚举可以作为位运算来进行与或运算,比如C ...

  6. ofbiz进击 第一节。 新建自己的webapp项目

    创建一个webapp的过程更新下来项目(直接从svn上面切下来就好),要先ant clean 下,然后在重新ant下.一: start sheel here :ant create-component ...

  7. Server.Transfer,Response.Redirect用法点睛

    Server.Transfer,Response.Redirect的区别 如果你读过很多行业杂志和 ASP.NET 示例,你会发现,大多数人使用 Response.Redirect 将用户引导到另一个 ...

  8. monkey测试(转)

    一.Monkey测试简介Monkey测试是Android平台自动化测试的一种手段,通过Monkey程序模拟用户触摸屏幕.滑动Trackball.按键等操作来对设备上的程序进行压力测试,检测程序多久的时 ...

  9. 关于设置oracle中系统编号SYSID自动编号的问题;

    http://liye9801.blog.163.com/blog/static/601970320086210039591/ 如何在oracle里设置自动编号列 2008-07-21 12:00:3 ...

  10. 移动widget开发

    发现Oracle----php连接有很多bug无法解决,只好转向php--连接mysql数据库,并装载了mysql两个文件,跟客户端NAVICAT_FOR_MYSQL,然后直接建表,用于测试,能够连通 ...