Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- using namespace std;
- int vp, vf;
- double r = 1, l = 0;
- double sep;
- double eps;
- double x;
- double fun(double x)
- {
- return ((sqrt(pow(1-sep, 2) + pow(x, 2)) / vp) + (sqrt(pow(sep, 2) + pow(1-x, 2)) / vf));
- }
- double tsearch(double l , double r, double eps)
- {
- if ((r - l) < eps)
- return (l + r) / 2;
- double a = (2 * l + r) / 3;
- double b = (l + 2 * r) / 3;
- if (fun(b) > fun(a))
- return tsearch(l, b, eps);
- else
- return tsearch(a, r, eps);
- }
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- cin >> vp >> vf;
- cin >> sep;
- eps = pow(10, -12);
- printf("%.10lf\n", tsearch(l, r, eps));
- //cout << tsearch(l, r, eps);
- }
Add Comment
Please, Sign In to add comment