-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10341.cpp
More file actions
45 lines (37 loc) · 732 Bytes
/
Copy path10341.cpp
File metadata and controls
45 lines (37 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <cstdio>
#include <cmath>
#define EPS 1e-7
using namespace std;
double p,q,r,s,t,u;
double f( double n )
{
return (p*exp(-n))+(q*sin(n))+(r*cos(n))+(s*tan(n))+(t*n*n)+(u);
}
double bisection()
{
double lo=0,hi=1,mid=0;
while( fabs(lo-hi)>EPS )
{
mid=(lo+hi)/2;
// cout<<f(lo)<<" "<<f(mid)<<endl;
if( f(lo)*f(mid) <= 0 )
hi=mid;
else
lo=mid;
// cout<<lo<<" "<<hi<<" "<<fabs(lo-hi)<<" "<<EPS<<endl;
}
return (lo+hi)/2;
}
int main()
{
while( scanf("%lf%lf%lf%lf%lf%lf",&p,&q,&r,&s,&t,&u)!=EOF )
{
// cout<<f(0)<<" "<<f(1)<<endl;
if( f(0)*f(1)>0 )
printf("No solution\n");
else
printf("%.4lf\n",bisection());
}
return 0;
}