HDU 3076:ssworld VS DDD(概率DP)
http://acm.split.hdu.edu.cn/showproblem.php?pid=3076
ssworld VS DDD
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.
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.
题意:两个人玩游戏,给出各自掷骰子得到不同点数的概率,点数小的扣一血,相同不扣血。
思路:概率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)的更多相关文章
- hdu 3076 ssworld VS DDD (概率dp)
///题意: /// A,B掷骰子,对于每一次点数大者胜,平为和,A先胜了m次A赢,B先胜了n次B赢. ///p1表示a赢,p2表示b赢,p=1-p1-p2表示平局 ///a赢得概率 比一次p1 两次 ...
- HDU 3076 ssworld VS DDD 概率dp,无穷级数,oj错误题目 难度:2
http://acm.hdu.edu.cn/showproblem.php?pid=3076 不可思议的题目,总之血量越少胜率越高,所以读取时把两人的血量交换一下 明显每一轮的胜率和负率都是固定的,所 ...
- hdu3076--ssworld VS DDD(概率dp第三弹,求概率)
ssworld VS DDD Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- hdu3076ssworld VS DDD 概率dp
//ssworld VS DDD 两个人有血量值 hp1 , hp2 //两人掷骰子得到每一点的概率已知 //ssword赢的概率 //dp[i][j] 表示有第一个人血量为i.第二个人的血量为j ...
- HDU 5781 ATM Mechine (概率DP)
ATM Mechine 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5781 Description Alice is going to take ...
- HDU 4050 wolf5x(动态规划-概率DP)
wolf5x Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- hdu 4405 Aeroplane chess (概率DP)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4336——Card Collector——————【概率dp】
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 3853:LOOPS(概率DP)
http://acm.split.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Problem Description Akemi Homura is a M ...
- HDU 4865 Peter's Hobby --概率DP
题意:第i天的天气会一定概率地影响第i+1天的天气,也会一定概率地影响这一天的湿度.概率在表中给出.给出n天的湿度,推测概率最大的这n天的天气. 分析:这是引自机器学习中隐马尔科夫模型的入门模型,其实 ...
随机推荐
- linux修改hostname
1.如果只是修改hostname可以通过如下命令 hostname newHostname 注意:这种修改方式只有当前有效,等服务器重启后hostname就会失效,回到原来的hostname. 2.如 ...
- set方法内存分析
// // main.m // 04-set方法的内存管理分析 // // Created by apple on 14-3-17. // // #import <Foundation/F ...
- Install .NET Framework 4.5.2 on a Cloud Service Role
October Guest OS rollout is starting today October 15 2015, and projected to be released on November ...
- 音乐播放器 AVAudioPlayer、定时器、UISlider
#import <UIKit/UIKit.h> #import <AVFoundation/AVFoundation.h> @interface ViewController ...
- 解决本地tomcat服务器内存不足问题
2014-6-25 9:47:48 org.apache.coyote.http11.Http11Processor process严重: Error processing requestjava.l ...
- 寻找第K大的数
在一堆数据中查找到第k个大的值. 名称是:设计一组N个数,确定其中第k个最大值,这是一个选择问题,解决这个问题的方法很多. 所谓“第(前)k大数问题”指的是在长度为n(n>=k)的乱序数组中S找 ...
- PAT 解题报告 1010. Radix (25)
1010. Radix (25) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 11 ...
- 解决Ueditor 不兼容IE7 和IE8
引用Ueditor的js 的时候用 绝对路径
- Lintcode: Segment Tree Query
For an integer array (index from 0 to n-1, where n is the size of this array), in the corresponding ...
- SNMP ber 编码
5.1 标识域(tag)的编码规则 标识域指明数据的类型,占用1个字节,常见的类型有:BOOL(0x01);INT(0x02);OCTSTR(0x04);NULL(0x05);OBJID(0x06); ...