简单概率....
Description Problem H 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
In front of you there are three doors. Two of them hide a cow, the other one hides your prize - a car. 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 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: NCOWS NCARS NSHOW Where NCOWS 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 <= NCOWS <= 10000 1 <= NCARS <= 10000 0 <= NSHOW < NCOWS
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 output0.66667 0.52500 0.71056
Source Root :: AOAPC II: Beginning Algorithm Contests (Second Edition) (Rujia Liu) :: Chapter 10. Maths :: Examples
Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 6. Mathematical Concepts and Methods Root :: AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) :: Chapter 2. Mathematics :: Probability :: Exercises: Beginner Root :: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim) :: Mathematics :: Probability Theory Root :: Competitive Programming: Increasing the Lower Bound of Programming Contests (Steven & Felix Halim) :: Chapter 5. Mathematics :: Probability Theory Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: Mathematics :: Probability Theory :: Standard |
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; double a,b,c; int main() { while(cin>>a>>b>>c) printf("%.5lf\n",(a/(a+b))*(b/(a+b-c-1))+(b/(a+b))*((b-1)/(a+b-c-1))); return 0; }