312B - Archer - CodeForces Solution


math probabilities *1300

Please click on ads to support us..

Python Code:

a,b,c,d=map(int,input().split())
start=(1-a/b)*(1-c/d)
current=start
result=start+1
while current > 0.000001 :
    current=current*start
    result+=current
print(result*a/b)

C++ Code:

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
#define ld long double
#define vll vector<int>
#define vpl vector<pair<int, int>>
#define pb push_back
#define all(n) n.begin(), n.end()
#define rev(n) reverse(n.begin(), n.end())
#define fr(n) for(int i=0; i<n; i++)
#define frl(k,n) for(int j=k; j<n; j++)
#define cinv(a,n) for(int j=0;j<n;j++) cin>>a[j]
#define yn(x) cout << ((x) ? "YES\n" : "NO\n")
#define endl '\n'
const int M = 1e9+7;

bool poweroftwo(int n) { return !(n & (n - 1)); }
int pow(int a, int b, int m=M) {int ans=1;while (b){if(b&1) ans=(ans*a)%m; a=(a*a)%m; b >>= 1;}return ans;}
// const int N = 4e4;
// bool seive[N]; vector<int> primes;
// void know_all_primes(){for(int i = 2; i < N; ++i){seive[i] = true;}for(int i = 2; i < N; ++i){if (seive[i]) {primes.push_back(i);for(int j = i *i; j < N; j += i){seive[j] = false;}}}}
vector<int> know_all_prime(int num) { vector<int> ans; for(int i=2; i*i<=num; i++) { if(num%i==0) { ans.push_back(i);} while (num % i == 0) { num /= i;}} if (num > 1){ ans.push_back(num); } return ans; }

mt19937 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());

void testCase(){
    // int n = 0, m = 0, c = 1, k = -1, sum = 0; string s; bool f = true;
    double a, b, c, d;
    cin >> a >> b >> c >> d;
    double cr = (1-a/b)*(1-c/d);
    cr = 1.0 - cr;
    a = a/b;
    cout << fixed << setprecision(6) << a/cr << endl;
}   

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int test = 1;
    // cin >> test;
    while(test--)  {testCase();}
    return 0;
}


Comments

Submit
0 Comments
More Questions

402. Remove K Digits
97. Interleaving String
543. Diameter of Binary Tree
124. Binary Tree Maximum Path Sum
1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
501A - Contest
160A- Twins
752. Open the Lock
1535A - Fair Playoff
1538F - Interesting Function
1920. Build Array from Permutation
494. Target Sum
797. All Paths From Source to Target
1547B - Alphabetical Strings
1550A - Find The Array
118B - Present from Lena
27A - Next Test
785. Is Graph Bipartite
90. Subsets II
1560A - Dislike of Threes
36. Valid Sudoku
557. Reverse Words in a String III
566. Reshape the Matrix
167. Two Sum II - Input array is sorted
387. First Unique Character in a String
383. Ransom Note
242. Valid Anagram
141. Linked List Cycle
21. Merge Two Sorted Lists
203. Remove Linked List Elements