这里没答案的情况怎么判断,我想复杂了,因为是单调函数,x的最大值和最小值带入方程同号肯定是没答案的,
否则肯定就是有答案的,还有就是这里二分的时候eps的大小,我设置的eps,1e-4,1e-5,1e-6都不过,1e-7才能过,
不知道为什么。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<set>
#include<map>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int maxn=1e3;
const double eps=1e-8;
const double e=2.71828;
double p,q,r,s,t,u;
double calc(double m)
{
return p*exp(-m)+q*sin(m)+r*cos(m)+s*tan(m)+t*m*m+u;
}
int main()
{
while(scanf("%lf%lf%lf%lf%lf%lf",&p,&q,&r,&s,&t,&u)!=EOF)
{
double x=0,y=1;
if(calc(x)*calc(y)>0)
{
cout<<"No solution"<<endl;
continue;
}
while(y-x>eps)
{
double m=x+(y-x)/2;
if(calc(m)>0)
x=m;
else
y=m;
}
printf("%.4f\n",x);
}
return 0;
}