-
Notifications
You must be signed in to change notification settings - Fork 14
/
10341.cpp
88 lines (74 loc) · 1.75 KB
/
10341.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <ctime>
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
#define PI acos(-1.0)
#define EPSILON 1e-5
#define EPS 1e-15
#define INF 1<<30
#define FOI(I, A, B) for (I=A; I<=B; I++)
#define FOD(I, A, B) for (I=A; I>=B; I--)
double p, q, r, s, t, u;
double fun(double x){
return p * exp(-x) + q * sin(x) + r * cos(x) + s * tan(x) + t * x * x + u;
}
double der(double x){
return -p * exp(-x) + q * cos(x) -r * sin(x) + s * 1/( cos(x) * cos(x) ) + 2 * t * x;
}
double Bisection(double lo, double hi){
double bot = fun(lo);
double top = fun(hi);
double mid = (lo + hi) / 2.0;
double cen = fun(mid);
if( bot * cen < -EPS )
return Bisection(lo, mid);
else if( top * cen < -EPS )
return Bisection(mid, hi);
else
return mid;
}
int main(){
//freopen("testI.txt", "r", stdin);
//freopen("testO.txt", "w", stdout);
while( scanf("%lf%lf%lf%lf%lf%lf", &p, &q, &r, &s, &t, &u) != EOF ){
double bot = fun(0.0);
double top = fun(1.0);
if( ( bot > EPS && top > EPS ) || ( bot < -EPS && top < -EPS ) )
printf("No solution\n");
else if( bot > -EPS && bot < EPS )
printf("0.0000\n");
else if( top > -EPS && top < EPS )
printf("1.0000\n");
else{
double x = Bisection(0.0, 1.0);
printf("%.4lf\n", x);
}
}
return 0;
}