HDU 5985 Lucky Coins 数学
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-Pj)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();
}
HDU 5985 Lucky Coins 数学的更多相关文章
- HDU 5985 Lucky Coins(概率)
http://acm.split.hdu.edu.cn/showproblem.php?pid=5985 题意:有多种类型的硬币,每种类型的硬币都有一定的数量,现在每次抛硬币,除去朝下的硬币,知道最后 ...
- HDU.5985.Lucky Coins(概率DP)
题目链接 \(Description\) 有n(n<=10)种硬币,已知每种硬币的数量和它抛一次正面朝上的概率pi.进行如下过程:每次抛一次所有硬币,将正面朝下的硬币去掉.重复该过程直到只剩一种 ...
- HDU 4937 Lucky Number (数学,进制转换)
题目 参考自博客:http://blog.csdn.net/a601025382s/article/details/38517783 //string &replace(iterator fi ...
- poj3519 Lucky Coins Sequence矩阵快速幂
Lucky Coins Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Lucky Coins Sequence
Lucky Coins Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 5985 概率
n种硬币各有cnt[i]枚,每轮下其有p[i]概率保留,问各种硬币只有它存活到最后一轮的概率. 设k轮后i硬币存活概率$a[i][k]=(1-p^k_i)^{cnt[i]}$ 则最后只有第i种硬币存活 ...
- HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)
HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...
- HDU 5985/nowcoder 207D - Lucky Coins - [概率题]
题目链接:https://www.nowcoder.com/acm/contest/207/D 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5985 ...
- 题解报告:hdu 1398 Square Coins(母函数或dp)
Problem Description People in Silverland use square coins. Not only they have square shapes but also ...
随机推荐
- python之多线程 threading.Lock() 和 threading.RLock()
0.目录 2. threading.Lock() 的必要性3.观察block4.threading.RLock() 的应用场景 1.参考 Thread Synchronization Mechanis ...
- [转]Java Web笔记:搭建环境和项目配置(MyEclipse 2014 + Maven + Tomcat)
来源:http://www.jianshu.com/p/56caa738506a 0. 绪言 Java Web开发中,除了基础知识外,开发环境搭建,也是一项基本功.开发环境包括了IDE.项目管理.项目 ...
- Telnet和SSH
1. 协议用途 Telnet和SSH用于远程访问服务器的的两大常用协议.利用它们,我们可以管理并监控生产服务器和企业服务器,更新服务器内核,安装最新的软件包和补丁,能够远程登录服务器,开展软件开发.测 ...
- 【原创】python 豆瓣采集
新手今天刚学python~~~ 有点凌乱~勉强看吧 只能算是给新手看看,见谅 简单版本的 豆瓣采集美图~~~~~~ 美女天天有 有木有~~~ python 3.4 sqlite3 BeautifulS ...
- 基于Kubernetes集群部署skyDNS服务
目录贴:Kubernetes学习系列 在之前几篇文章的基础,(Centos7部署Kubernetes集群.基于kubernetes集群部署DashBoard.为Kubernetes集群部署本地镜像仓库 ...
- HDU5692 Snacks DFS序 线段树
去博客园看该题解 题目 HDU5692 Snacks Problem Description 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的 ...
- ArrayList类中的contains()方法底层依赖的是equals()方法
ArrayList类中的contains()方法底层依赖的是equals()方法.若集合中的元素是自定义对象,则应该重写该类父类Object的equals()方法,否则对象永远都不相同(因为都是new ...
- log4j快速入门
转自:http://blog.csdn.net/yanwushu/article/details/7581255 1.引言 在应用程序中添加日志记录总的来说基于三个目的: .监视代码中变量的变化情况, ...
- day8数据类型补充,集合,深浅拷贝
思维导图: 集合的补充:下面的思维导图有一个点搞错了,在这里纠正一下,没有合集,是反交集,^这个是反差集的意思 . 交集&,反交集^,差集-,并集|,然后就是子集和超集 数据类型补充: ''' ...
- 使用PHPStorm 配置自定义的Apache与PHP环境
使用PHPStorm 配置自定义的Apache与PHP环境之一 关于phpstorm配置php开发环境,大多数资料都是直接推荐安装wapmserver.而对于如何配置自定义的PHP环境和Apach ...