mhdew

Contest 5_G

Feb 28th, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. int p, q, r, s, t, u;
  5.  
  6. double solve(double x)
  7. {
  8.     double val=p*exp(-x)+q*sin(x)+r*cos(x)+s*tan(x)+t*x*x+u;
  9.  
  10.     return val;
  11. }
  12.  
  13. int main()
  14. {
  15.   //  freopen("INPUT.txt", "r", stdin);
  16.   //  freopen("OUTPUT.txt", "w", stdout);
  17.     while(scanf("%d%d%d%d%d%d", &p,&q,&r,&s,&t,&u)!=EOF){
  18.         double left=solve(0);
  19.         double right=solve(1.0);
  20.  
  21.         if((left*right)>0)
  22.             printf("No Solution\n");
  23.         else{
  24.             double l=0.0;
  25.             double h=1.0;
  26.             double ans;
  27.             for(int i=0;i<100;i++){
  28.                 double mid=(l+h)/2.0;
  29.                 double key=solve(mid);
  30.  
  31.                 if(key>0){
  32.                     l=mid;
  33.                 }
  34.                 else
  35.                     h=mid;
  36.             }
  37.             printf("%.4lf\n", l);
  38.         }
  39.     }
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment