Advertisement
erfanul007

UVa 10341

Dec 9th, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<cmath>
  3. using namespace std;
  4.  
  5. double p, q, r, s, t, u;
  6.  
  7. float sol(float x)
  8. {
  9. return p*exp(-x)+q*sin(x)+r*cos(x)+s*tan(x)+t*pow(x,2.0)+u;
  10. }
  11.  
  12. int main()
  13. {
  14. while(scanf("%lf %lf %lf %lf %lf %lf",&p,&q,&r,&s,&t,&u)!=EOF){
  15. double l=0,m=0.5,h=1,xm,xh;
  16. while(h-l>0.0000001){
  17. m=(l+h)/2;
  18. xm=sol(m);
  19. xh=sol(h);
  20. if((xh<0 && xm>0)||(xh>=0 && xm>xh)||(xh<=0 && xh>xm)){
  21. l=m;
  22. }
  23. else{
  24. h=m;
  25. }
  26. }
  27. if(abs(xm)<=0.0001)
  28. printf("%1.4f\n",m);
  29. else
  30. printf("No solution\n");
  31. }
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement