Skip to content

Instantly share code, notes, and snippets.

Created February 24, 2010 16:58
Show Gist options
  • Select an option

  • Save anonymous/313613 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/313613 to your computer and use it in GitHub Desktop.
#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