UVa 10491 cows and Cars: probabilities and generalized three-problem

Source: Internet
Author: User
Tags time limit

10491-cows and Cars

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_ problem&problem=1432

In television contests, participants are often asked to choose one out of set of or doors for example, one or several of W Hich leads to different prizes. In this problem we'll deal with a specific kind of such a contest. Suppose you are given the following challenge by the contest presenter:

In front of there are three doors. Two of them hide a cow, the other one hides your prize-a car. After your choose a door, but before you open it, I'll give you a 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'll then be able to choose if you are want to keep your, or if you choice to the other wish unopened. You'll win whatever is behind the door your open. In this example, the probability your have of winning the car is 2/3 (as hard as it's to believe), assuming you always SWI TCH your choice when the presenter gives your opportunity to does so (after he shows for you, a door with a cow). The reason of this number (2/3) is this-if your had chosen one of the two cows, you would surely switch to the car, since The presenter had shown you cow. If you are 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 is only 1/3, but that isn ' t imp Ortant for this problem.

In this problem, your are to calculate the probability your have of winning the car, for a generalization of the problem Abo VE:-The number of cows is variable

-The number of cars are variable (number of cows + number of cars = total number of doors)

-The number of doors hiding cows that presenter opens for your are variable (several doors may still Re given the opportunity to change your choice)

You are should assume that your always decide to switch your choice to all other's unopen doors after the presenter You are some doors with cows behind it.

Input

There are several test cases for your the to process. Each test case consists of the three integers on a line and separated by whitespace. Each line has the following format:ncows ncars nshow Where ncows are the number of doors with cows, ncars is the number of Doors with cars and nshow are the number of doors the presenter opens for your before you choose to switch to another unope n Door. The limits for your program are:1 <= ncows <= 10000 1 <= ncars <= 10000 0 <= nshow < ncows

Output

For each of the "test cases," are to output a line containing just one value-the probability of winning the car Assumi ng you switch to another unopen door and displayed to 5 decimal places.

Sample input

2 1 1
5 3 2
2000 2700 900
0.66667
0.52500

0.71056

"Historical Introduction"

The three-way question (Monty Hall problem) is also known as the Monty Hall problem, the Montejo problem or the Hall paradox, which is largely from the American video game show Let's make a Deal. The problem name comes from the program's moderator Monte Holl (Monty Hall). Contestants will see three closed doors, one of which has a car behind it, and a door with a car behind it to win the car, and a goat behind the other two doors. When the contestant chooses a door, but does not open it, the host opens one of the remaining two doors, exposing one of the goats. The moderator will then ask the contestants if they want to change another door that is still closed. The question is: will switching to another door increase the chances of a competitor winning a car?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.