CF 312B (Archer-proportional Sequence Limit summation)

Source: Internet
Author: User

B. Archer
Time limit per test2 seconds
Memory limit per test256 megabytes
Inputstandard input
Outputstandard output
SmallR is an archer. smallR is taking a match of archer with Zanoes. they try to shoot in the target in turns, and SmallR shoots first. the probability of shooting the target each time is for SmallR while for Zanoes. the one who shoots in the target first shoshould be the winner.

Output the probability that SmallR will win the match.

Input
A single line contains four integers.

Output
Print a single real number, the probability that SmallR will win the match.

The answer will be considered correct if the absolute or relative error doesn' t exceed 10 seconds-limit 6.

Sample test (s)
Input
1 2 1 2
Output
0.666666666667

 


Proportional sequence infinite summation formula a + ap ^ 2 +... 0 <p <1 --> S = a/(1-p)

 

 

 


[Cpp] # include <cstdio>
# Include <cstdlib>
# Include <cstring>
# Include <iostream>
# Include <algorithm>
# Include <functional>
# Include <cmath>
# Include <cctype>
Using namespace std;
# Define For (I, n) for (int I = 1; I <= n; I ++)
# Define Rep (I, n) for (int I = 0; I <n; I ++)
# Define Fork (I, k, n) for (int I = k; I <= n; I ++)
# Define ForD (I, n) for (int I = n; I --)
# Define Forp (x) for (int p = pre [x]; p = next [p])
# Define RepD (I, n) for (int I = n; I> = 0; I --)
Int main ()
{
// Freopen (". in", "r", stdin );
// Freopen (". out", "w", stdout );
Double a, B, c, d;
Cin> a> B> c> d;
Printf ("%. 12lf \ n", a/B/(1-(1-a/B) * (1-c/d )));

Return 0;
}

# Include <cstdio>
# Include <cstdlib>
# Include <cstring>
# Include <iostream>
# Include <algorithm>
# Include <functional>
# Include <cmath>
# Include <cctype>
Using namespace std;
# Define For (I, n) for (int I = 1; I <= n; I ++)
# Define Rep (I, n) for (int I = 0; I <n; I ++)
# Define Fork (I, k, n) for (int I = k; I <= n; I ++)
# Define ForD (I, n) for (int I = n; I --)
# Define Forp (x) for (int p = pre [x]; p = next [p])
# Define RepD (I, n) for (int I = n; I> = 0; I --)
Int main ()
{
// Freopen (". in", "r", stdin );
// Freopen (". out", "w", stdout );
Double a, B, c, d;
Cin> a> B> c> d;
Printf ("%. 12lf \ n", a/B/(1-(1-a/B) * (1-c/d )));
 
Return 0;
}

 

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.