Morass

Rep

Aug 29th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. double p,q,r,s,t,u;
  5.  
  6. bool valid(double x)
  7. {
  8.     return (p*exp(-x)+q*sin(x)+r*cos(x)+s*tan(x)+t*x*x+u)>0;
  9. }
  10.  
  11. int main(){
  12.  
  13.     while(cin>>p>>q>>r>>s>>t>>u){
  14.         if(p*exp(-1)+q*sin(1)+r*cos(1)+s*tan(1)+t+u>1e-12||p+r+u<0){
  15.             printf("No solution\n");
  16.             continue;
  17.         }
  18.         double s=0, e=1;
  19.         while(fabs(e-s)>1e-15)
  20.         {
  21.             double mid=(s+e)/2;
  22.             if(valid(mid)) s=mid;
  23.             else e=mid;
  24.         }
  25.         printf("%.4f\n",s);
  26.     }
  27.  
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment