Created
February 24, 2010 16:58
-
-
Save anonymous/313613 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <cmath> | |
| #include <cstdio> | |
| using namespace std; | |
| int p, q, r, s, t, u; | |
| double f(double x) | |
| { | |
| return p*exp(-x) + q*sin(x) + r*cos(x) + s*tan(x) + t*x*x + u; | |
| } | |
| int main() | |
| { | |
| while(cin >> p >> q >> r >> s >> t >> u) | |
| { | |
| double rb = 1.0; | |
| double lb = 0.0; | |
| double mid = (rb + lb) / 2.0; | |
| if(f(lb) * f(rb) > 0) | |
| cout << "No solution\n"; | |
| else | |
| { | |
| int cnt = 0; | |
| while(cnt < 24) | |
| { | |
| if(f(lb) * f(mid) > 0) | |
| lb = mid; | |
| else | |
| rb = mid; | |
| mid = (lb + rb) / 2.0; | |
| cnt++; | |
| } | |
| cout << mid+1e-8 << "\n"; | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment