#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
int p,q,r,s,t,u;
double compute(double x)
{
return p*exp(-1*x) + q*sin(x) + r*cos(x) + s*tan(x) + t*x*x + u ;
}
int main()
{
//freopen("in.txt","r",stdin);
while(scanf("%d%d%d%d%d%d",&p,&q,&r,&s,&t,&u)!=EOF)
{
double x=0,y=1,m;
if(compute(0)<0||compute(1)>0)
{
cout<<"No solution"<<endl;
continue;
}
while(y-x>1e-12)
{
m=(y+x)/2.0;
if(compute(m)>0)
x=m;
else if(compute(m)<0)
y=m;
else break;
}
printf("%.4lf\n",m);
}
return 0;
}
这个题就是用二分查找,然后因为是double,所以要控制精度。另外exp()函数刚学到。
UVA 10341 - Solve It
最新推荐文章于 2019-04-14 10:25:47 发布