Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <stdio.h>
- using namespace std;
- const int MN = 10000 + 10;
- const double fi = (sqrt(5.0) - 1.0) / 2.0;
- const double inf = 1e9;
- struct point {
- double x, y;
- point(double dx, double dy) {
- x = dx;
- y = dy;
- };
- point() {
- };
- };
- int n;
- point a[MN][2];
- double d[MN];
- inline double kos(point a, point b, point c) {
- point v1(b.x - a.x, b.y - a.y), v2(c.x - a.x, c.y - a.y);
- return fabs(v1.x * v2.y - v1.y * v2.x);
- }
- double dist(point a, point b) {
- return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
- }
- inline double f(double x, double y) {
- double mx = -1e20;
- point p(x, y);
- for(int i = 0; i < n; i ++)
- mx = max(mx, kos(p, a[i][0], a[i][1]) / d[i]);
- return mx;
- }
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- cin >> n;
- for(int i = 0; i < n; i ++) {
- cin >> a[i][0].x >> a[i][0].y >> a[i][1].x >> a[i][1].y;
- d[i] = dist(a[i][0], a[i][1]);
- }
- double left_x = -inf;
- double right_x = inf;
- double x1, y1, x2, y2, rez1, rez2, l_y, left_y, right_y;
- double l_x = right_x - left_x;
- x1 = right_x - l_x * fi;
- x2 = left_x + l_x * fi;
- for(int i = 0; i < 150; i ++) {
- left_y = -inf;
- right_y = inf;
- l_y = right_y - left_y;
- y1 = right_y - l_y * fi;
- y2 = left_y + l_y * fi;
- rez1 = f(x1, y1);
- rez2 = f(x2, y2);
- for(int j = 0; j < 150; j ++) {
- if (rez1 > rez2) {
- left_y = y1;
- y1 = y2;
- rez1 = rez2;
- l_y = right_y - left_y;
- y2 = left_y + l_y * fi;
- rez2 = f(x2, y2);
- }
- else {
- right_y = y2;
- y2 = y1;
- rez2 = rez1;
- l_y = right_y - left_y;
- y1 = right_y - l_y * fi;
- rez1 = f(x1, y1);
- }
- }
- rez1 = f(x1, (right_y + left_y) / 2.0);
- rez2 = f(x2, (right_y + left_y) / 2.0);
- if (rez1 > rez2) {
- left_x = x1;
- x1 = x2;
- rez1 = rez2;
- l_x = right_x - left_x;
- x2 = left_x + l_x * fi;
- rez2 = f(x2, y2);
- }
- else {
- right_x = x2;
- x2 = x1;
- rez2 = rez1;
- l_x = right_x - left_x;
- x1 = right_x - l_x * fi;
- rez1 = f(x1, y1);
- }
- }
- printf("%0.18lf %0.18lf", (right_x + left_x) / 2.0, (right_y + left_y) / 2.0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement