daily pastebin goal
87%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include<algorithm>
  5.  
  6. using namespace std;
  7.  
  8. const long double MIN = 0.0000000000, MAX = 1e9;
  9. int n, m;
  10. int a[1000], b[1000];
  11.  
  12. bool func(long double x) {
  13.     for (int i = 0; i < n; i++) {
  14.         x -= (long double) (x + m) / a[i];
  15.         if (x <= 0.0)
  16.             return false;
  17.         x -= (long double) (x + m) / b[i];
  18.     }
  19.  
  20.     return true;
  21. }
  22.  
  23. int main() {
  24.     cin >> n;
  25.     cin >> m;
  26.  
  27.     for (int i = 0; i < n; i++) {
  28.         cin >> a[i];
  29.     }
  30.  
  31.     for (int i = 0; i < n; i++) {
  32.         cin >> b[i];
  33.     }
  34.  
  35.     long double l = MIN, r = MAX;
  36.  
  37.     while (r - l > 1) {
  38.         long double m = (r + l) / 2;
  39.         if (func(m))
  40.             r = m;
  41.         else
  42.             l = m;
  43.     }
  44.    
  45.     cout << r;
  46.  
  47.     /*system("pause");*/
  48.  
  49.     return 0;
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top