Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 129
- #include <iostream>
- #include <math.h>
- #include <string>
- using namespace std;
- long double zn(int vp, int vf, long double a, long double x)
- {
- long double z;
- z = sqrt((1 - a)*(1 - a) + x*x) / vp + sqrt(a*a + (1 - x)*(1 - x)) / vf;
- return z;
- }
- long double tern(int vp, int vf, long double a)
- {
- long double gp, gl, gop, gol;
- gp = 1;gl = 0;
- while (gp - gl > 0.000000000001)
- {
- gop = gl + (gp - gl) / 3 * 2; gol = gl + (gp - gl) / 3;
- if (zn(vp, vf, a, gol) > zn(vp, vf, a, gop))
- gl = gol;
- else if (zn(vp, vf, a, gol) < zn(vp, vf, a, gop))
- gp = gop;
- else
- {
- gp = gop;
- gl = gol;
- }
- }
- return gl;
- }
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int vp, vf;
- long double a;
- cin >> vp >> vf >> a;
- cout.precision(8);
- cout << fixed << tern(vp, vf, a);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement