UVa 10491 Cows and Cars

42 篇文章 0 订阅
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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

概率~

比a+b还短的代码……

感觉大多数博客的翻译都有歧义,给出一个自认为比较好理解的:

在a+b扇门后面,有a头牛,b辆车,第一次你选择一扇门,这扇门就被排除在外,然后又有c扇后面是牛的门被排除,求从剩下的(a+b-c-1)扇门中选一扇,选到车的概率。

分类讨论: 若刚开始选的是车,这种选择的概率是b/(a+b),然后再选到车的概率是(b-1)/(a+b-c-1),刚开始选的是牛同理,总概率为(a*b+b*b-b)/(a+b-c-1)/(a+b)~


#include<cstdio>

double a,b,c,ans;

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


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值