// UVa 10341 - Solve It #include <iostream> #include <stdio.h> #include <math.h> using namespace std; double p, q, r, s, t, u; double epsilon = 0.0000001; double f(double x) { return p * exp(-x) + q * sin(x) + r * cos(x) + s * tan(x) + t * x * x + u; } double bisection(double left, double right) { while (left + epsilon < right) { double mid = (left + right) / 2; if (f(left) * f(mid) <= 0) right = mid; else left = mid; } return left; } int main() { while (cin >> p >> q >> r >> s >> t >> u) { if (f(0) * f(1) > 0) cout << "No solution" << endl; else printf("%.4f\n", bisection(0, 1)); } return 0; }
Thursday, July 16, 2015
UVa 10341 - Solve It
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment