11181 - Probability|Given
N friends go to the local super market together. The probability of their buying something from the
market is p 1 ,p 2 ,p 3 ,...,p N respectively. After their marketing is finished you are given the information
that exactly r of them has bought something and others have bought nothing. Given this information
you will have to find their individual buying probability.
Input
The input file contains at most 50 sets of inputs. The description of each set is given below:
First line of each set contains two integers N (1 ≤ N ≤ 20) and r (0 ≤ r ≤ N). Meaning of N and
r are given in the problem statement. Each of the next N lines contains one floating-point number p i
(0.1 < p i < 1) which actually denotes the buying probability of the i-th friend. All probability values
should have at most two digits after the decimal point.
Input is terminated by a case where the value of N and r is zero. This case should not be processes.
Output
For each line of input produce N +1 lines of output. First line contains the serial of output. Each of the
next N lines contains a floating-point number which denotes the buying probability of the i-th friend
given that exactly r has bought something. These values should have six digits after the decimal point.
Follow the exact format shown in output for sample input. Small precision errors will be allowed. For
reasonable precision level use double precision floating-point numbers.
Sample Input
3 2
0.10
0.20
0.30
5 1
0.10
0.10
0.10
0.10
0.10
0 0
Sample Output
Case 1:
0.413043
0.739130
0.847826
Case 2:
0.200000
0.200000
0.200000
0.200000
0.200000
题意:
有 n 个人准备去逛超市,其中第 i 人购物的概率是 Pi ,逛完以后得知有 r 人买了东西,根据这一信息,计算每人买了东西的实际概率。
x[i] 表示 第i个人是否买了东西 1买了0没买
然后用 next_permutation();
把所有的情况 表示出来
在暴力求解了。。。条件概率,贝叶斯公式
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
double r[];
double sum[];
int x[];
double tot;
int n,m;
void init(){
memset(r,,sizeof(r));
memset(sum,,sizeof(sum));
memset(x,,sizeof(x));
for(int i=;i<n-m;i++){
x[i]=;
}
tot=;
for(int i=;i<n;i++){
cin>>r[i];
}
}
int main(){
int k=;double temp=0.0;
while(cin>>n>>m&&n+m){
init();
do{
temp=;
for(int i=;i<n;i++){
if(x[i])temp*=r[i];
else temp*=-r[i];
}
tot+=temp;
for(int i=;i<n;i++){
if(x[i])sum[i]+=temp;
}
}while(next_permutation(x,x+n));
cout<<"Case "<<k++<<":"<<endl;
for(int i=;i<n;i++){
printf("%f\n",sum[i]/tot);
}
}
}
11181 - Probability|Given的更多相关文章
- 概率论 --- Uva 11181 Probability|Given
Uva 11181 Probability|Given Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.acti ...
- uva 11181 - Probability|Given(概率)
题目链接:uva 11181 - Probability|Given 题目大意:有n个人去超市买东西,给出r,每个人买东西的概率是p[i],当有r个人买东西的时候,第i个人恰好买东西的概率. 解题思路 ...
- uva 11181 - Probability|Given
条件概率公式:P( A|B ) = P( AB ) / P( B ) 表示在事件B发生的前提,事件A发生的可能性: 问题的: 复位事件E:r个人买东西: 事件Ei:文章i个人买东西: 的要求是P( E ...
- UVa 11181 - Probability|Given(条件概率)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 11181 Probability|Given (离散概率)
题意:有n个人去商场,其中每个人都有一个打算买东西的概率P[i].问你最后r个人买了东西的情况下每个人买东西的概率 题解:一脸蒙蔽的题,之前的概率与之后的概率不一样??? 看了白书上的题解才知道了,其 ...
- Uva - 11181 Probability|Given (条件概率)
设事件B为一共有r个人买了东西,设事件Ai为第i个人买了东西. 那么这个题目实际上就是求P(Ai|B),而P(Ai|B)=P(AiB)/P(B),其中P(AiB)表示事件Ai与事件B同时发生的概率,同 ...
- UVA - 11181 Probability|Given (条件概率)
题意:有n个人,已知每个人买东西的概率,求在已知r个人买了东西的条件下每个人买东西的概率. 分析:二进制枚举个数为r的子集,按定义求即可. #include<cstdio> #includ ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
随机推荐
- 模仿jquery的一些实现 第二版
具体如下: //w作为window的形参,就表示window (function(w) { // 定义一个全局的window.wyl变量,就类似于jquery里的$,Jquery对象 w.wyl; / ...
- PHPExcel 生成excel统计表格
db.php为数据库操作类, $config为数据库配置,PHPExcel版本为PHPExcel_1.8.0, php代码: $dir = dirname(__FILE__); require $d ...
- os.path.exists(path) 和 os.path.lexists(path) 的区别
使用os.path.exists()方法可以直接判断文件是否存在.代码如下:>>> import os>>> os.path.exists(r'C:\1.TXT') ...
- VC中TRACE()的用法
个人总结:最近看网络编程是碰到了TRACE语句,不知道在哪里输出,查了一晚上资料也没找出来,今天终于在CSDN上找到了,真是个高地方啊,方法如下: 1.在MFC中加入TRACE语句 2.在TOOLS- ...
- (step5.1.3)hdu 1213( How Many Tables——1213)
题目大意:输入两个整数n,m.分别表示点数.对点的操作的次数.在接下来的m行中,每行有两个整数a,b.表示a和b是好朋友.(不是好朋友的不能坐在同一个桌子上) .求需要多少张桌子 解题思路:并查集 1 ...
- C#高级编程随笔
1.把类创作的变量叫做对象2.类就是对象的模版3.类定义了每个对象的数据和功能4.接口不能被实例化,抽象类不能被实例化5.抽象基类可以包含非抽象方法,而接口只能包含抽象方法6.一个类可以实现多个接口7 ...
- 版本管理工具:linux下svn的基本使用
参考: linux下安装SVN http://jingyan.baidu.com/article/3c343ff7039de20d37796306.html svn客户端使用linux篇 ht ...
- c/c++字符数组和字符串大揭秘
第一:写这篇文章源于我对'\0'和“\0”的探讨 当我对char a []="\0"; int size_a=sizeof(a); //结果为2 当时我很纳闷字符串不是以'\0'结 ...
- 使用apache benchmark(ab) 测试报错汇总
1.socket: Too many open files (24) 解决方法: [root@zabbix ~]# ulimit -a core file size (blocks, -c) 0 da ...
- 我的Python成长之路---GitHub使用克隆GitHub(SSH key配置)
六.克隆GitHub仓库 1.创建仓库目录,目录位置没有要求,比如D:\learngit. 2.配置ssh(如果不配置会每次都输入用户名和密码) 使用TortoiseGit生成ssh-key:开始菜单 ...