uva 10491 uva 10491 Cows and Cars

输入a,b,c,  a牛,b车,知情人会一次性打开c个门(注意是一次性全部打开c个门,要是一次打开一个的那完全不同了,另外还注意一点,如果你选的就是牛,虽然知情人能打开c个门,但是它不能打开你那个,而题目有一个条件 0<=c<a  , 这说明即便你选了一个牛,知情人还是能打开c个门的,是另外的c个门)

1.第一次选择牛,概率为a/(a+b),然后知情人打开了c个门(自己选的那个不被打开),然后现在实际上只剩下a+b-c个门(包括自己选的那个)。改变选择,那么现在能选的门的个数为a+b-c-1,选到车的概率为b/(a+b-c-1)。由于是条件概率所以要相乘  p1=a/(a+b)  *  b/(a+b-c-1) 

 

2.如果第一次选到车,概率为b/(a+b),然后知情人打开c个门,实际上剩下的门也是a+b-c。改变选择,那么能选的个数为a+b-c-1,车的个数只剩下b-1(你放弃了之前选择的那个),选到车的概率就是  (b-1)/(a+b-c-1) , 两者相乘  p2=b/(a+b) * (b-1)/(a+b-c-1)

 

3.  ans=p1+p2


/***********************************************
 * Author: fisty
 * Created Time: 2015/3/3 16:02:30
 * File Name   : uva10491.cpp
 *********************************************** */
#include <iostream>
#include <cstring>
#include <deque>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <algorithm>
using namespace std;
#define Debug(x) cout << #x << " " << x <<endl
#define Memset(x, a) memset(x, a, sizeof(x))
const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef pair<int, int> P;
#define FOR(i, a, b) for(int i = a;i < b; i++)
    
int main() {
    //freopen("in.cpp", "r", stdin);
    int a, b, c;
    while(~scanf("%d%d%d", &a, &b, &c)){
       double p1 = 1.*a*b/((a+b)*(a+b-c-1));
       double p2 = 1.*b*(b-1)/((a+b)*(a+b-c-1));
       printf("%.5f\n",p1 + p2);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值