-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva10341.cpp
More file actions
63 lines (52 loc) · 1.28 KB
/
uva10341.cpp
File metadata and controls
63 lines (52 loc) · 1.28 KB
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
/* Rishikesh
* UVA 10341
*/
#include<iostream>
#include<string>
#include<sstream>
#include<iomanip>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cstdint>
#include<numeric>
#include<stack>
#include<queue>
#include<list>
#include<deque>
#include<bitset>
#include<cmath>
using namespace std;
double func(vector<int>& v, double x) {
return v[0] * exp(-x) + v[1] * sin(x) + v[2]*cos(x) + v[3] * tan(x) + v[4] * x * x + v[5];
}
int main() {
string s;
while(getline(cin, s), s.length() > 5) {
istringstream iss(s);
vector<int> v(6);
for(int i = 0; i < 6; i++) iss >> v[i];
double left = 0, right = 1;
double lf=func(v,left), rf=func(v,right), mid, mf;
if (lf * rf > 0) {
printf("No solution\n");
} else {
do {
mid = (left + right)/2;
mf = func(v, mid);
if (mf * lf > 0) {
left = mid;
lf = mf;
}
else {
right = mid;
rf =mf;
}
} while (abs(mf) > 1e-9);
int ans = round(10000*mid);
printf("%d.%04d\n", ans/10000,ans%10000);
}
}
}