UVa10341 Solve It

观察表达式和数据范围,发现这是个单调递减函数……

那么直接二分答案就可以了。

精度要到1e-7以下

 

 1 /*by SilverN*/
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<cmath>
 7 using namespace std;
 8 const double eps=1e-7;
 9 int p,q,r,s,t,u;
10 double f(double x){
11     return p*exp(-x)+q*sin(x)+r*cos(x)+s*tan(x)+t*x*x+u;
12 }
13 int main(){
14     while(scanf("%d%d%d%d%d%d",&p,&q,&r,&s,&t,&u)!=EOF){
15         double l=0,r=1;
16         if(f(l)<-eps || f(r)>eps){
17             printf("No solution\n");continue;
18         }
19         while(fabs(l-r)>eps){
20             double mid=(l+r)/2;
21             double res=f(mid);
22             if(res>0)l=mid;
23             else r=mid;
24         }
25         printf("%.4f\n",l);
26     }
27     return 0;
28 }

 

posted @ 2017-01-19 13:53  SilverNebula  阅读(109)  评论(0编辑  收藏  举报
AmazingCounters.com