UVa 10491 Cows and Cars
The effect of this question is this:
There is a a+b door in front of you, where a fan is behind a cow, and the B fan is behind a car. You can choose a door, but not open it. At this time the host (guest) will help you open another C fan behind the cow's door, and then you make a choice, is to continue to choose the door or another open door. What we need to answer is, in the case of always choosing "another one", what is the probability of a car behind the chosen door?
Data range:
1<=a<=10000, 1<=b<=10000, 0<=c<a.
This is a probability of the calculation problem, generally this topic is mainly to push the formula, pushed out after it is very good to do, the following outlines the idea:
1> if the first choice of the door is a cow, the probability is a A/(A+B), then the host to help out the C cow, the rest of a common a+b-c-1 fan door, at this time to re-select the car is the probability of B/(a+b-c-1), then the total probability is a*b/(a+b-c-1) * (A+B).
2> if the first choice of the door is a car, the probability is b/(a+b), then the host to help out the C cow, the rest of a common a+b-c-1 fan door, at this time to re-select the car is the probability is (b-1)/(a+b-c-1), then the total probability is b* (b-1)/(A +B-C-1) * (a+b).
That would always be the sums of the two, namely b* (a+b-1)/(a+b-c-1) * (a+b). The code is as follows:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int main ()
{
int a,b,c;
while (~SCANF ("%d%d%d", &a,&b,&c))
{
double s;
if (!b | | a+b==c+1) s=0;//has no car or only one car and is selected at the beginning, the probability of re-selecting is 0 else s= (double) ((double) (b*
(a+b-1))/(double) ((a+b-c-1 ) * (a+b));
printf ("%0.5lf\n", s);
}
return 0;
}