Last active
November 16, 2022 19:21
-
-
Save AKASH-ALAM/586aa8613cd83e0c6865aa3b5971d687 to your computer and use it in GitHub Desktop.
UVA 10341- Solve It
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Author : Pnictogen | |
* Task : | |
* Algo : | |
**/ | |
#include <bits/stdc++.h> | |
#define endl '\n' | |
#define sqr(x) (x) * (x) | |
#define gcd(x,y) __gcd(x,y) | |
#define lcm(x,y) ((x/gcd(x,y)) * y) | |
#define sz(x) (int)x.size() | |
#define all(x) (x).begin(),(x).end() | |
#define rall(x) (x).rbegin(),(x).rend() | |
#define prec(x) fixed<<setprecision(x) | |
#define min3(a,b,c) min(a,min(b,c)) | |
#define max3(a,b,c) max(a,max(b,c)) | |
#define min4(a,b,c,d) min(a,min(b,min(c,d))) | |
#define max4(a,b,c,d) max(a,max(b,max(c,d))) | |
#define unsyncIO ios_base::sync_with_stdio(false); cin.tie(nullptr) | |
using namespace std; | |
using ll = long long; | |
using db = double; | |
using ld = long double; | |
using ull = unsigned long long; | |
const ld PI = acos((ld) - 1); | |
const int MOD = 1e9 + 7; | |
const ll INF = 2e18 + 1; | |
const ld EPS = 1e-9; | |
const int MX = 2e5; | |
#ifdef LOCAL | |
#include"debug.h" | |
#else | |
#define debug(...) | |
#endif | |
ld p, q, r, s, t, u; | |
ld method(ld x) { | |
return (p * (1 / exp(x))) + q * sin(x) + r * cos(x) + s * tan(x) + (t * pow(x, 2)) + u; | |
} | |
void solve() { | |
while (cin >> p >> q >> r >> s >> t >> u) { | |
if (method(1) * method(0) > 0) { // this condition is based by bisection method(if you don't know it, search for it) | |
cout << "No solution" << endl; | |
} else { // find root(x) using binary search | |
ld low = 0.0, high = 1.0, x, ans; | |
cout << fixed << setprecision(4); | |
while (low < high) { | |
x = (low + high) / 2.0; | |
ans = method(x); | |
if (ans < 0) high = x - EPS; // for non increasing funtion | |
else low = x + EPS; // for decreasing function | |
} | |
cout << x << endl; | |
} | |
} | |
} | |
int main() { | |
#ifdef LOCAL | |
clock_t tStart = clock(); | |
freopen("in.txt", "r", stdin); | |
freopen("out.txt", "w", stdout); | |
#endif | |
unsyncIO; | |
int T = 1; //cin >> t; | |
while (T--) { | |
solve(); | |
} | |
#ifdef LOCAL | |
cerr << "\nRuntime: " << (ld) (clock() - tStart) / CLOCKS_PER_SEC << " Seconds" << endl; | |
#endif | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment