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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
| #include<iostream> #include<cstring> #include<vector> #include<queue> #include<string> #include<algorithm> #include<cmath> #include<cstdio> #include<set> #include<map> ##define put putchar ##define ls(a) (a << 1) ##define rs(a) (a << 1 | 1) ##define pii pair<int, int>
using namespace std;
const int N = 5e4 + 10; const double eps = 1e-10;
int n, cnt = 0; double S = 1e6;
int sign(double a) { if(fabs(a) < eps) return 0; return a > 0 ? 1 : -1; } struct point { double x, y; point (const double& x0 = 0, const double& y0 = 0) : x(x0), y(y0) { } point operator + (const point& t) const { return point(x + t.x, y + t.y); } point operator - (const point& t) const { return point(x - t.x, y - t.y); } point operator * (const double& t) const { return point(x * t, y * t); } point operator / (const double& t) const { return point(x / t, y / t); } point rotate() { return point(y, -x); } } p[N], low, q[N], ans[5];
double dot(const point& a, const point& b) { return a.x * b.x + a.y * b.y; } double cross(const point& a, const point& b) { return a.x * b.y - a.y * b.x; } double len(const point& a) { return sqrt(dot(a, a)); } double dis(const point &a, const point &b) { return sqrt(dot(a - b, a - b)); }
struct line { point a, b; double ang; line() {} line(point A, point B){ a = A, b = B; ang = atan2((b - a).y, (b - a).x); } bool operator < (const line& t) const { if(sign(ang - t.ang) == 0) return sign(cross(t.a - a, t.b - a)) == 1; return ang < t.ang; } } ;
template<class T> inline void read(T &x) { T res = 0, f = 1; char cc = getchar(); while(! isdigit(cc)) { if(cc == '-') f = -1; cc = getchar(); } while(isdigit(cc)) res = (res << 1) + (res << 3) + cc - 48, cc = getchar(); x = res * f; return ; } template<class T, class ...T1> inline void read(T &x, T1 &...x1) { read(x), read(x1...); return ; } template<class T> inline void write(T x) { if(x < 0) x = -x, put('-'); if(x > 9) write(x / 10); put(x % 10 + 48); return ; } template<> inline void write(char x) { put(x); return ; } template<class T, class ...T1> inline void write(T x, T1 ...x1) { write(x),write(x1...); return ; } template <class T> inline bool chkmax(T &x, T y) { return x < y ? x = y , 1 : 0; } point get_ins(line a, line b) { double s1 = cross(b.b - a.a, a.b - a.a), s2 = cross(b.a - a.a, a.b - a.a); return {(s1 * b.a.x - s2 * b.b.x) / (s1 - s2), (s1 * b.a.y - s2 * b.b.y) / (s1 - s2)}; } bool cmp(point a, point b) { if(sign(cross(a - low, b - low)) > 0) return true; if(sign(cross(a - low, b - low)) == 0 && sign(dis(low, a) - dis(low, b)) < 0) return true; return false; } bool check(point a, point b, point c) { return sign(cross(b - a, c - b)) <= 0; } void get_conv() { sort(p + 1, p + n + 1, cmp); q[++ cnt] = low; for(int i = 1; i <= n; ++ i) { if(sign(p[i].x - low.x) == 0 && sign(p[i].y - low.y) == 0) continue; while(cnt > 1 && check(q[cnt - 1], q[cnt], p[i])) -- cnt; q[++ cnt] = p[i]; } q[cnt + 1] = q[1]; return ; } void get_ans(int i, int t, int l, int r) { ans[1] = get_ins(line(q[l], q[l] + (q[i + 1] - q[i]).rotate()), line(q[i], q[i + 1])); ans[2] = get_ins(line(q[r], q[r] + (q[i + 1] - q[i]).rotate()), line(q[i], q[i + 1])); ans[3] = get_ins(line(q[r], q[r] + (q[i + 1] - q[i]).rotate()), line(q[t], q[t] + q[i + 1] - q[i])); ans[4] = get_ins(line(q[l], q[l] + (q[i + 1] - q[i]).rotate()), line(q[t], q[t] + q[i + 1] - q[i])); return ; }
signed main() { read(n), low.y = 1e6; for(int i = 1; i <= n; ++ i) scanf("%lf%lf", &p[i].x, &p[i].y), low = (sign(p[i].y - low.y) < 0 || (sign(p[i].y - low.y) == 0 && sign(p[i].x - low.x) < 0)) ? p[i] : low; get_conv(); for(int i = 1, t = 2, l = 2, r = 2; i <= cnt; ++ i) { double d = dis(q[i], q[i + 1]); while(sign(cross(q[t] - q[i], q[t] - q[i + 1]) - cross(q[t + 1] - q[i], q[t + 1] - q[i + 1])) < 0) t = t % cnt + 1; l = t; while(sign(dot(q[r + 1] - q[r], q[i + 1] - q[i])) > 0) r = r % cnt + 1; while(sign(dot(q[l + 1] - q[l], q[i + 1] - q[i])) < 0) l = l % cnt + 1; double res = cross(q[i + 1] - q[i], q[t] - q[i]) * (d + fabs(dot(q[i + 1] - q[i], q[r] - q[i + 1]) / d) + fabs(dot(q[l] - q[i], q[i + 1] - q[i]) / d)) / d; if(sign(res - S) < 0) S = res, get_ans(i, t, l, r); } printf("%lf\n", S); for(int i = 1; i <= 4; ++ i) { double x = ans[i].x, y = ans[i].y; if(sign(x) == 0) x = 0.0; if(sign(y) == 0) y = 0.0; printf("%lf %lf\n", x, y); } return 0; }
|