Advertisement
Pabon_SEC

Solve It

May 9th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define EPS 1e-7
  3.  
  4. using namespace std;
  5.  
  6. int p,q,r,s,t,u;
  7.  
  8. double func(double x)
  9. {
  10.     return p*exp(-x) + q*sin(x) + r*cos(x) + s*tan(x) + t*x*x + u;
  11. }
  12.  
  13. double bisection()
  14. {
  15.     double low=0,high=1,mid;
  16.  
  17.     while(low+EPS<high)
  18.     {
  19.         mid = (low+high)/2;
  20.  
  21.         if(func(low)*func(mid)<=0)
  22.         {
  23.             high = mid;
  24.         }
  25.         else
  26.         {
  27.             low = mid;
  28.         }
  29.     }
  30.  
  31.     return mid;
  32. }
  33.  
  34. int main()
  35. {
  36.     while(scanf("%d%d%d%d%d%d",&p,&q,&r,&s,&t,&u)!=EOF)
  37.     {
  38.         double ans = func(0)*func(1);
  39.  
  40.         if(ans>0)
  41.         {
  42.             printf("No solution\n");
  43.         }
  44.         else
  45.         {
  46.             printf("%.4f\n",bisection());
  47.         }
  48.     }
  49.  
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement