Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <bitset>
- #include <cassert>
- #include <cmath>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <iostream>
- #include <list>
- #include <map>
- #include <queue>
- #include <set>
- #include <string>
- #include <sstream>
- #include <vector>
- #include <complex>
- #include <ctime>
- #include <stack>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef vector<int> VI;
- typedef vector< VI > VVI;
- typedef pair<int, int> PII;
- typedef vector<PII> VPII;
- #define REP(i, n) for(int i = 0; i < (n); ++i)
- #define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
- #define FOR(i, x, y) for(int i = (x); i <= (y); ++i)
- #define RFOR(i, x, y) for(int i = (x); i >= (y); --i)
- #define SZ(a) (int)(a).size()
- #define ALL(a) (a).begin(),(a).end()
- #define SORT(a) sort(ALL(a))
- #define CLEAR(x) memset(x, 0, sizeof x);
- #define COPY(FROM, TO) memcpy(TO, FROM, sizeof TO);
- #define UNIQUE(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())
- #define pb push_back
- #define mk make_pair
- #define sqr(x) ((x)*(x))
- #define X first
- #define Y second
- const long double pi=acos(-1.0);
- const double EPS = 1E-9;
- const int inf = 1e+9;
- const int NMAX = 1e+5;
- const int MOD = (1e+9) + 9;
- double x, y, c;
- struct pt {
- double x, y;
- pt () {}
- pt (double x_, double y_) : x(x_), y(y_) {}
- bool operator< (const pt & p) const {
- return x < p.x-EPS || abs(x-p.x) < EPS && y < p.y - EPS;
- }
- };
- struct line {
- double a, b, c;
- line() {}
- line (pt p, pt q) {
- a = p.y - q.y;
- b = q.x - p.x;
- c = - a * p.x - b * p.y;
- norm();
- }
- void norm() {
- double z = sqrt (a*a + b*b);
- if (abs(z) > EPS)
- a /= z, b /= z, c /= z;
- }
- double dist (pt p) const {
- return a * p.x + b * p.y + c;
- }
- };
- #define det(a,b,c,d) (a*d-b*c)
- inline bool betw (double l, double r, double x) {
- return min(l,r) <= x + EPS && x <= max(l,r) + EPS;
- }
- inline bool intersect_1d (double a, double b, double c, double d) {
- if (a > b) swap (a, b);
- if (c > d) swap (c, d);
- return max (a, c) <= min (b, d) + EPS;
- }
- bool intersect (pt a, pt b, pt c, pt d, pt & left, pt & right) {
- if (! intersect_1d (a.x, b.x, c.x, d.x) || ! intersect_1d (a.y, b.y, c.y, d.y))
- return false;
- line m (a, b);
- line n (c, d);
- double zn = det (m.a, m.b, n.a, n.b);
- if (abs (zn) < EPS) {
- if (abs (m.dist (c)) > EPS || abs (n.dist (a)) > EPS)
- return false;
- if (b < a) swap (a, b);
- if (d < c) swap (c, d);
- left = max (a, c);
- right = min (b, d);
- return true;
- }
- else {
- left.x = right.x = - det (m.c, m.b, n.c, n.b) / zn;
- left.y = right.y = - det (m.a, m.c, n.a, n.c) / zn;
- return betw (a.x, b.x, left.x)
- && betw (a.y, b.y, left.y)
- && betw (c.x, d.x, left.x)
- && betw (c.y, d.y, left.y);
- }
- }
- double f (double len) {
- double A = sqrt (sqr(x) - sqr(len));
- double B = sqrt (sqr(y) - sqr(len));
- pt x1(0.0, 0.0), x2(0.0, 0.0);
- intersect (pt (len, 0), pt (0, A), pt(0, 0), pt (len, B), x1, x2);
- return x1.y;
- }
- double binary_search () {
- double first = 0, last = min (x, y) + 1;
- double mid;
- while (first < last) {
- if (last - first < 1e-7)
- return (last - first) / 2.0 + first;
- mid = (last - first) / 2.0 + first;
- double high = f (mid);
- if (high > c)
- first = mid;
- else
- last = mid;
- }
- return last;
- }
- int main () {
- while (scanf ("%lf %lf %lf", &x, &y, &c) != EOF) {
- printf ("%.3lf\n", binary_search ());
- }
- return 0;
- }
- /*
- 30 40 10
- 12.619429 8.163332 3
- 10 10 3
- 10 10 1
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement