Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. 129
  2. #include <iostream>
  3. #include <math.h>
  4. #include <string>
  5. using namespace std;
  6.  
  7. long double zn(int vp, int vf, long double a, long double x)
  8. {
  9.     long double z;
  10.     z = sqrt((1 - a)*(1 - a) + x*x) / vp + sqrt(a*a + (1 - x)*(1 - x)) / vf;
  11.     return z;
  12.  
  13. }
  14.  
  15.  
  16. long double tern(int vp, int vf, long double a)
  17. {
  18.     long double gp, gl, gop, gol;
  19.     gp = 1;gl = 0;
  20.     while (gp - gl > 0.000000000001)
  21.     {
  22.         gop = gl + (gp - gl) / 3 * 2; gol = gl + (gp - gl) / 3;
  23.         if (zn(vp, vf, a, gol) > zn(vp, vf, a, gop))
  24.             gl = gol;
  25.         else if (zn(vp, vf, a, gol) < zn(vp, vf, a, gop))
  26.             gp = gop;
  27.         else
  28.         {
  29.             gp = gop;
  30.             gl = gol;
  31.         }
  32.  
  33.  
  34.     }
  35.  
  36.  
  37.     return gl;
  38.  
  39. }
  40.  
  41.  
  42. int main()
  43. {
  44.     freopen("input.txt", "r", stdin);
  45.     freopen("output.txt", "w", stdout);
  46.  
  47.     int  vp, vf;
  48.     long double a;
  49.  
  50.     cin >> vp >> vf >> a;
  51.     cout.precision(8);
  52.     cout << fixed << tern(vp, vf, a);
  53.  
  54.  
  55.  
  56.  
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement