很水的一道题,因为你发现这个函数是单调递减的,所以二分法求出函数的根即可。

 1 #include <cstdio>
 2 #include <cmath>
 3 //using namespace std;
 4 
 5 const double e = 1e-14;
 6 double p, q, r, s, t, u;
 7 
 8 inline double f(double x)
 9 { return p*exp(-x) + q*sin(x) + r*cos(x) + s*tan(x) + t*x*x + u; }
10 
11 int main()
12 {
13     //freopen("in.txt", "r", stdin);
14 
15     while(scanf("%lf%lf%lf%lf%lf%lf", &p, &q, &r, &s, &t, &u) == 6)
16     {
17         if(f(0)<-e || f(1)>e) { puts("No solution"); continue; }
18         double L = 0, R = 1, m;
19         for(int i = 0; i < 30; i++)
20         {
21             m = (L+R)/2;
22             if(f(m) < 0) R = m;
23             else L = m;
24         }
25         printf("%.4f\n", m);
26     }
27 
28     return 0;
29 }
代码君

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-04
  • 2022-12-23
  • 2022-12-23
  • 2021-05-22
  • 2022-12-23
猜你喜欢
  • 2021-07-11
  • 2021-12-07
  • 2021-10-25
  • 2022-12-23
  • 2021-12-09
  • 2021-09-14
相关资源
相似解决方案