UVA 10491 Cows and Cars

Source: Internet
Author: User

Original question:
In television contests, participants is often asked to choose one from a set of or doors for example,
One or several of which leads to different prizes. In this problem we'll deal with a specific kind of such
A contest. Suppose you is given the following challenge by the contest presenter:
In front of there is three doors. 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 being able to choose if you want to keep your choice, or if you wish-to-the other unopened
Door. You'll win whatever is behind the door open.
In this example, the probability you has the winning the car is 2/3 (as hard as it's to believe),
Assuming your choice when the presenter gives you the opportunity
He shows you a door with a cow). The reason of this number (2/3) are this-if you had chosen one of
The cows, would surely switch to the car, since the presenter had shown your the other cow. If
You had chosen the car and you would switch to the remaining cow, therefore losing the prize. Thus, in
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, and that isn ' t important for this problem.
In this problem, you is to calculate the probability you have the 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 are variable (several doors may
Still is open when given the opportunity to change your choice)
You should assume, that's decide to switch your choice to any other of the unopen doors
After the presenter shows your some doors with cows behind it.
Input
There is 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:
Ncows Ncars Nshow
Where Ncows is the number of doors with cows, ncars are the number of doors with cars and
Nshow is the number of doors the presenter opens for your before you choose to switch to another
Unopen door.
The limits for your program is:
1≤ncows≤10000
1≤ncars≤10000
0≤nshow < Ncows
Output
For each of the test cases, you is to output a line containing just one value-the probability of winning
The car assuming you switch to another unopen door and displayed to 5 decimal places.
Sample Input
2 1 1
5 3 2
2000 2700 900
Sample Output
0.66667
0.52500
0.71056
Effect:
You take part in a TV show, the host gives you a n+m door, there are n doors behind is the cow, the door behind M is the car, you choose a door now, then the host tells show the door is cattle, and then you choose the other than the current outside the door, ask you to choose the probability of the car is how much.

 #include <iostream> #include <algorithm> #include <map> #include < string> #include <cstring> #include <sstream> #include <cstdio> #include <vector> #include <cmath> #include <stack> #include <queue> #include <iomanip> #include <set> #include <
Fstream> #include <climits> using namespace std;



FStream input,output;
    int main () {Ios::sync_with_stdio (false);
    Double cow,car,show; while (cin>>cow>>car>>show) {cout<<setprecision (5) <<fixed<<cow/(Cow+car) *c
    ar/(car+cow-show-1) +car/(cow+car) * (car-1)/(cow+car-show-1) <<endl;
}//Input.close ();
    Output.close ();
return 0; }

Answer:
This is the beginning of the wrong, thought you every time you choose, the host will only tell you one of the door behind a cow. Turtle did not do a day, and finally look at other people's work, the results found incredibly simple. As a programming problem, you don't even have to use the loop. = =
is actually a full probability formula, because you are selected two times, so divided into the first to choose the probability of the cow, and first selected the probability of the car.
If you come up with a cow and the host tells you that there is a cow behind the show, then the probability of selecting the cow by the first choice is multiplied by the number of doors minus the number of tips of the host, minus your current selection of the cow, the probability of choosing the car, the probability of choosing a car multiplied by the number of tips minus the number of Two plus together.

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.