UVA10491 Cows and Cars【概率】

In television contests, participants are often asked to choose one from a set of or doors for example, one or several of which lead to different prizes. In this problem we will deal with a specific kind of such a contest. Suppose you are given the following challenge by the contest presenter:
????In front of you there are three doors. Two of them hide a cow, the other one hides your prize - a car. After you choose a door, but before you open it, I will give you an hint, by opening one of the doors which hides a cow (I’ll never open the door you have chosen, even if it hides a cow). You will then be able to choose if you want to keep your choice, or if you wish to change to the other unopened door. You will win whatever is behind the door you open.
????In this example, the probability you have of winning the car is 2/3 (as hard as it is to believe), assuming you always switch your choice when the presenter gives you the opportunity to do so (after he shows you a door with a cow). The reason of this number (2/3) is this - if you had chosen one of the two cows, you would surely switch to the car, since the presenter had shown you the other cow. If you had chosen the car, you would switch to the remaining cow, therefore losing the prize. Thus, in two out of three cases you would switch to the car. The probability to win if you had chosen to stick with your initial choice would obviously be only 1/3, but that isn’t important for this problem.
????In this problem, you are to calculate the probability you have of winning the car, for a generalization of the problem above:
????? The number of cows is variable
????? The number of cars is variable (number of cows + number of cars = total number of doors)
????? The number of doors hiding cows that the presenter opens for you is variable (several doors may still be open when you are given the opportunity to change your choice)
????You should assume that you always decide to switch your choice to any other of the unopen doors after the presenter shows you some doors with cows behind it.
Input
There are several test cases for your program to process. Each test case consists of three integers on a line, separated by whitespace. Each line has the following format:
????NCOW S NCARS NSHOW
????Where NCOW S is the number of doors with cows, NCARS is the number of doors with cars and NSHOW is the number of doors the presenter opens for you before you choose to switch to another unopen door.
????The limits for your program are:
????1 ≤ NCOW S ≤ 10000
????1 ≤ NCARS ≤ 10000
????0 ≤ NSHOW < NCOW S
Output
For each of the test cases, you are to output a line containing just one value - the probability of winning the car assuming you switch to another unopen door, displayed to 5 decimal places.
Sample Input
2 1 1
5 3 2
2000 2700 900
Sample Output
0.66667
0.52500
0.71056

问题链接UVA10491 Cows and Cars
问题简述:(略)
问题分析
????总共有a+b扇门,a扇后面是牛,b扇后面是车。选择一扇门后,主持人打开另外c扇门,然后你再选一扇,求是车的概率。
1.先选牛:a/(a+b),还剩a+b-c-1扇门,其中b扇为车,所以a/(a+b)b/(a+b-c-1)
2.先选车:b/(a+b),还剩a+b-c-1扇门,其中b-1扇为车,所以b/(a+b)
(b-1)/(a+b-c-1)
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA10491 Cows and Cars */

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a, b, c;
    while(scanf("%d %d %d", &a, &b, &c) != EOF)
        printf("%.5lf\n", 1.0 *(a + b - 1) / (a + b) * b / ((a + b) - c - 1));

    return 0;
}

原文地址:https://www.cnblogs.com/tigerisland45/p/10377075.html

时间: 2024-10-17 00:50:37

UVA10491 Cows and Cars【概率】的相关文章

UVA10491 - Cows and Cars(概率)

题目链接 题目大意:给你n个门后面藏着牛,m个门后面藏着车,然后再给你k个提示,在你作出选择后告诉你有多少个门后面是有牛的,现在问你作出决定后,根据提示改变你的选择能够成功的概率. 解题思路:简单的概率题,题目意思懂了应该没什么问题. 代码: #include <cstdio> #include <cstring> int main () { double n, m, k; while (scanf ("%lf%lf%lf", &n, &m, &

UVA 10491 Cows and Cars 数学 概率

题目链接: https://vjudge.net/problem/UVA-10491 题目描述: 有a头牛, b辆车, 在你的一次选择后主持人会为你打开C扇有牛的门并问你换门还是不换门, 输出总是换门情况下可以获得车的概率 解题思路: 我现在还没有写代码......我不知道我的思路对不对, 但是先说一下, 我们可以分情况来讨论, 然后分情况乘上获得换门情况下获得车的概率, 也就是全概率公式, 情况分成两种, 一开始指着车, 和一开始指着牛 , res = a/(a+b) * b/(a+b-c-1

uva 10491 Cows and Cars

https://vjudge.net/problem/UVA-10491 题意: a头牛,b辆车,每扇门后面都有一头牛或一辆车 开始选手选择一扇门 然后主持人打开c扇有牛的门(选中的除外) 然后选手换一扇门 问最后选手选的门后面是车的概率 开始选牛的概率: 牛/总 又换到车的概率: 车/(总-c-1) 开始选车的概率: 车/总 又换到车的概率: (车-1)*(总-c-1) 总概率: 牛/总  *   车/(总-c-1)   +    车/总  *  (车-1)*(总-c-1) #include<

《算法竞赛入门经典——训练指南》第二章题库

UVa特别题库 UVa网站专门为本书设立的分类题库配合,方便读者提交: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=442 注意,下面注有"extra"的习题并没有在书中出现,但在上面的特别题库中有,属于附加习题. 基础练习 (Basic Problems) UVa11388 GCD LCM UVa11889 Benefit UVa10943 How do y

算法竞赛入门10.2计数与概率基础例题代码

10.6 Irrelevant Elements UVA1635 思路:基础组合计数 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> const int N = 1e5+5; using namespace std; long long C[N][20]; int prime[20][2]; inline int judge(int x,int m,int k) {

UVA&amp;&amp;POJ离散概率练习[3]

POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问题 |00|+|01|=|0| 注意序列是环形 // // main.cpp // poj3869 // // Created by Candy on 25/10/2016. // Copyright © 2016 Candy. All rights reserved. // #include <i

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

百度啊哈放假哈是否可拉伸交罚款了萨芬

http://www.ebay.com/cln/bya9700/cars/167373057012/2015.02.01 http://www.ebay.com/cln/w.ka053/cars/167170359019/2015.02.01 http://www.ebay.com/cln/y-we561/cars/167640056015/2015.02.01 http://www.ebay.com/cln/bin9178/cars/167511984011/2015.02.01 http:/

百度的附件是甲方可拉伸了开发

http://www.ebay.com/cln/yf25396/cars/167277998010/2015.02.09 http://www.ebay.com/cln/huan-con/cars/167393960016/2015.02.09 http://www.ebay.com/cln/rua-don/cars/167549052015/2015.02.09 http://www.ebay.com/cln/zal9627/cars/167278006010/2015.02.09 http: