HDU 5985 概率问题
2017-09-07 22:06
176 查看
概率问题
题意: 有n种硬币,现在有一个方法可以得出一个或者一种lucky硬币,所有硬币抛下然后去掉背面朝上的,继续抛直到只剩一种硬币或者没有硬币为止。问每一种硬币成为lucky的概率是多少。
思路:
若想知道在某一步只剩下第i种硬币的话,需要知道其它硬币已经没有的概率。
定义:die[i][j]表示第i种硬币在第j次抛全部被去掉的概率,很容易得出(1−pk)cnt 其中p为每次抛掷正面朝上的概率, cnt为这一种硬币的数量,k为第k次抛掷。
定义:alive[i][j] 表示第i种硬币在第j抛掷之后仍然有正面朝上的概率,很明显为1−die[i][k] .
那么对于求出第i种硬币的答案,在k次抛掷和k+1次抛掷中其它种类已经全部被去掉,而第i中硬币存在的概率,了即(alive[i][k]−alive[i][k+1])∗temp ,其中temp为其它种类的消失的概率。
#include <iostream> #include <cstdio> #include <cstring> #include <math.h> #include <algorithm> using namespace std; const int maxn = 1000005; int n; double die[maxn][111]; double alive[maxn][111]; double ans[maxn]; double Pow(double x,int n) { double ans=1.0; while(n) { if(n&1) { ans*=x; } x*=x; n/=2; } return ans; } int main() { // freopen("in.txt","r",stdin); int t; scanf("%d",&t); while(t--) { scanf("%d",&n); double p; int cnt; for(int i = 1;i <= n; i++) { scanf("%d%lf",&cnt,&p); double temp; for(int j = 1;j <= 100; j++) { temp = (1.0-Pow(p,j)); temp = Pow(temp,cnt); die[i][j] = temp; alive[i][j] = 1-temp; } } if(n == 1) { printf("1.000000\n"); continue; } memset(ans,0,sizeof(ans)); for(int i = 1;i <= n; i++) { for(int k = 1;k <= 100; k++) { double temp = 1; for(int j = 1;j <= n; j++) { if(i == j) continue; temp *= die[j][k]; } ans[i] += (alive[i][k]-alive[i][k+1])*temp; } } printf("%.6f",ans[1]); for(int i = 2;i <= n; i++) { printf(" %.6f",ans[i]); } printf("\n"); } return 0; }
相关文章推荐
- HDU 1203 I NEED A OFFER![动态规划——01背包问题+简单概率]
- HDU-5985-Lucky Coins(概率)
- HDU 5985 Lucky Coins(概率)
- HDU 1203 I NEED A OFFER!(01背包概率问题)
- HDOJ(HDU) 2201 熊猫阿波的故事(概率问题)
- 动态规划 ③ HDU - 1203 I NEED A OFFER! 背包问题+独立事件概率
- HDOJ(HDU) 2201 熊猫阿波的故事(概率问题)
- HDU 5985 Lucky Coins (概率)
- HDU 2955 Robberies(01背包的概率问题)
- hdu 5985 Lucky Coins (概率)
- HDU 4089 Activation(11年北京 概率问题)
- hdu_5139 概率问题
- hdu 1204 糖果大战(概率问题 markov 过程)
- hdu_5139 概率问题
- HDU 2955 Robberies(经典01背包概率问题)
- 【解题报告】 HDU 4405 Aeroplane chess - 递推概率问题,从后往前推算即可得到期望
- HDU 5985 Lucky Coins(概率)
- HDU 3853 LOOPS(概率DP简单题)
- hdu 1284 钱币兑换问题
- HDU 1276 士兵队列训练问题