Lucky Coins

题目连接:

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

Description

Bob has collected a lot of coins in different kinds. He wants to know which kind of coins is lucky. He finds out a lucky kind of coins by the following way. He tosses all the coins simultaneously, and then removes the coins that come up tails. He then tosses all the remaining coins and removes the coins that come up tails. He repeats the previous step until there is one kind of coins remaining or there are no coins remaining. If there is one kind of coins remaining, then this kind of coins is lucky. Given the number of coins and the probability that the coins come up heads after tossing for each kind, your task is to calculate the probability for each kind of coins that will be lucky.

Input

The first line is the number of test cases. For each test case, the first line contains an integer k representing the number of kinds. Each of the following k lines describes a kind of coins, which contains an integer and a real number representing the number of coins and the probability that the coins come up heads after tossing. It is guaranteed that the number of kinds is no more than 10, the total number of coins is no more than 1000000, and the probabilities that the coins come up heads after tossing are between 0.4 and 0.6.

Output

For each test case, output a line containing k real numbers with the precision of 6 digits, which are the probabilities of each kind of coins that will be lucky.

Sample Input

3
1
1000000 0.5
2
1 0.4
1 0.6
3
2 0.4
2 0.5
2 0.6

Sample Output

1.000000
0.210526 0.473684
0.124867 0.234823 0.420066

Hint

题意

有一堆硬币,每回合为正面的概率为P,每回合我们都会去掉当前翻面为反面的硬币。

问每种硬币剩到只剩下一个的概率是多少。

保证 0.4<P<0.6

题解:

给了概率的范围,显然这道题就是模拟扔就行了,随便扔个几十回合,这个概率就会降到很小的范围。

第i个硬币第j回合全死掉的概率为 (1-P^j)^num[i]

活下来的概率当然是1-死掉的。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 15;
int n;
double num[maxn],ans[maxn],p[maxn];
double count_die(int x,int y){return pow(1-pow(p[x],y),num[x]);
}
double count_live(int x,int y){return 1-count_die(x,y);
}
void solve(){scanf("%d",&n);memset(ans,0,sizeof(ans));for(int i=0;i<n;i++)cin>>num[i]>>p[i];if(n==1){printf("1.000000\n");return;}for(int i=1;i<100;i++){for(int j=0;j<n;j++){double tmp = 1;for(int k=0;k<n;k++){if(k==j)continue;tmp*=count_die(k,i);}ans[j]+=(count_live(j,i)-count_live(j,i+1))*tmp;}}for(int i=0;i<n;i++)if(i==0)printf("%.6f",ans[i]);else printf(" %.6f",ans[i]);printf("\n");
}
int main(){int t;scanf("%d",&t);while(t--)solve();
}

转载于:https://www.cnblogs.com/qscqesze/p/7151148.html

HDU 5985 Lucky Coins 数学相关推荐

  1. 牛客每日练习----骑行川藏,Lucky Coins,不凡的夫夫

    大提琴的声音就像一条河,左岸是我无法忘却的回忆,右岸是我值得紧握的璀璨年华,中间流淌的,是我年年岁岁淡淡的感伤. 链接:https://ac.nowcoder.com/acm/problem/1765 ...

  2. HDU——1013(字符串+数学)Digital Roots

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1013 题意:给你一个整数列表,让位数上的数相加得到一个新的数,若为个位数则输出,若不为个位数重复此操作 ...

  3. 枚举 + 进制转换 --- hdu 4937 Lucky Number

    Lucky Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) T ...

  4. HDU 4611 Balls Rearrangement 数学

    Balls Rearrangement 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4611 Description Bob has N balls ...

  5. hdu 4937 Lucky Number(数学题 进制转换)2014多校训练第7场

    Lucky Number                                                                          Time Limit: 20 ...

  6. hdu 1398 Square Coins/hdu 1028 Ignatius and the Princess III

    两道母函数的模板题: http://acm.hdu.edu.cn/showproblem.php?pid=1398 View Code #include<iostream>#include ...

  7. HDU 1398 Square Coins

    母函数简单应用 题目: Square Coins Problem Description People in Silverland use square coins. Not only they ha ...

  8. hdu 5312 Sequence(数学推导——三角形数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5312 Sequence Time Limit: 2000/2000 MS (Java/Others)  ...

  9. HDU 6217 BBP Formula (数学)

    题目链接: HDU 7217 题意: 题目给你可以计算 \(π\) 的公式: \(\pi = \sum_{k=0}^{\infty}[\frac{1}{16^k}(\frac{4}{8k+1})-(\ ...

最新文章

  1. 35岁中年博士失业,决定给后辈一些建议!
  2. python画函数曲线-python画蝴蝶曲线图的实例
  3. oc基础-foundation框架中的常用结构体
  4. 王道 ——线程概念和多线程模型
  5. jmeter jdbc mysql_jmeter获取JDBC响应做接口关联(三)
  6. Canvas的基本用法
  7. 不会写漂亮代码不是优秀的程序员,没有钢铁侠之躯不是合格的程序员
  8. mysql学习一 常用语句
  9. 联想哪款服务器性能,联想深腾7000高性能服务器
  10. struts2与json的整合
  11. spring-第九篇之高级依赖关系配置
  12. Android 10 使用PreferenceScreen的方法
  13. 迪普交换机恢复出厂设置_迪普产品配置文档-基础篇(2012-11-05).pdf
  14. 动态规划解决完全背包问题(cpp)
  15. 关于win10 system进程 占用CPU过高的问题?
  16. 什么是云计算,什么是网格计算,他们之间有什么区别
  17. Parcelable encountered IOException
  18. MarkdownPad 2 安装配置及常见问题
  19. 断点续传的原理(转)
  20. 全国计算机等级考试二级C语言考试题

热门文章

  1. 非常干货之Python资源大全
  2. Nginx 的 Location 配置指令块
  3. Web前端开发——BAT面试题汇总及答案03
  4. Oracle 中调用外部C动态库函数
  5. 01 安装ansible
  6. hdu 3037 Lucas定理
  7. 利用记录型信号量解决不会出现死锁的哲学家就餐问题
  8. ubuntu下安装RabbitVCS(失败记录)
  9. WPF地区选择控件(内附下载地址)
  10. DataCapa 启动