Poj 3525 most distant point from the sea-the farthest point on the coast-half plane

Source: Internet
Author: User
/* Poj 3525 most distant point from the sea-finding the farthest point on the coast-the semi-Plane Cross is to find the radius of the inner circle of the polygon that has the largest inner circle. The enumerated radius pushes all the coast along the normal vector to the inner radius. distance, calculate the intersection by plane. If the polygon has a core, the radius will exist */# include <stdio. h> # include <math. h ># include <algorithm> using namespace STD; const double EPS = 1e-9; struct point {Double X, Y; point () {} Point (double A, double B ): X (A), y (B) {}} Dian [803]; point Jiao [803]; struct line {point S, E; double angle;} Xian [803]; int N, Yong; bool mo_ee (Double X, Double Y) {double ret = x-y; If (Ret <0) ret =-ret; If (Ret <EPS) return 1; return 0;} bool mo_gg (Double X, Double Y) {return x> Y + EPS;} // x> Y bool mo_ll (Double X, Double Y) {return x <Y-EPS;} // x <y bool mo_ge (Double X, Double Y) {return x> Y-EPS ;} // x> = y bool mo_le (Double X, Double Y) {return x <Y + EPS;} // x <= y point mo_intersection (point u1, point U2, point V1, point V2) {point ret = U1; Double T = (u1.x-v1.x) * (v1.y-v2.y)-(u1.y-v1.y) * (v1.x-v2.x )) /(u1.x-u2.x) * (v1.y-v2.y)-(u1.y-u2.y) * (v1.x-v2.x); ret. X + = (u2.x-u1.x) * t; ret. Y + = (u2.y-u1.y) * t; return ret;} double mo_xmult (point P2, point P0, Point P1) // P1 returns a negative value on the left of P2, return positive {return (p1.x-p0.x) * (p2.y-p0.y)-(p2.x-p0.x) * (p1.y-p0.y);} void mo_hpi_addl (point a, point B) on the right) {Xian [Yong]. S = A; Xian [Yong]. E = B; Xian [Yong]. angle = atan2 (B. y-a.y, B. x-a.x); Yong ++;} // half plane bool mo_hpi_cmp (const line & A, const line & B) {If (mo_ee (. angle, B. angle) {return mo_gg (mo_xmult (B. e,. s, B. s), 0);} else {return mo_ll (. angle, B. angle) ;}} int mo_hpi_dq [803]; bool mo_hpi_isout (line cur, line Top, line top_1) {point Jiao = mo_intersection (top. s, top. e, top_1.s, top_1.e); Return mo_ll (mo_xmult (cur. e, Jiao, cur. s), 0); // If the clockwise direction is mo_gg} int mo_halfplaneintersect (line * Xian, int N, point * Jiao) {int I, j, ret = 0; sort (Xian, Xian + N, mo_hpi_cmp); for (I = 0, j = 0; I <n; I ++) {If (mo_gg (xian [I]. angle, Xian [J]. angle) {Xian [++ J] = Xian [I] ;}} n = J + 1; mo_hpi_dq [0] = 0; mo_hpi_dq [1] = 1; int Top = 1, bot = 0; for (I = 2; I <n; I ++) {While (top> bot & mo_hpi_isout (xian [I], xian [mo_hpi_dq [Top], Xian [mo_hpi_dq [Top-1]) Top --; while (top> bot & mo_hpi_isout (xian [I], xian [mo_hpi_dq [bot], Xian [mo_hpi_dq [bot + 1]) BOT ++; mo_hpi_dq [++ top] = I; // current half-plane inbound stack} while (top> bot & mo_hpi_isout (xian [mo_hpi_dq [bot], Xian [mo_hpi_dq [Top], xian [mo_hpi_dq [Top-1]) Top --; while (top> bot & mo_hpi_isout (xian [mo_hpi_dq [Top], Xian [mo_hpi_dq [bot], xian [mo_hpi_dq [bot + 1]) BOT ++; mo_hpi_dq [++ top] = mo_hpi_dq [bot]; for (ret = 0, I = Bot; I <top; I ++, RET ++) {Jiao [RET] = mo_intersection (xian [mo_hpi_dq [I + 1]. s, Xian [mo_hpi_dq [I + 1]. e, Xian [mo_hpi_dq [I]. s, Xian [mo_hpi_dq [I]. e);} return ret;} // returns the point mo_getfaxian (point xiang) {point A; If (mo_ee (Xiang. x, 0) {. X = 1;. y = 0; return a;} else if (mo_ee (Xiang. y, 0) {. X = 0;. y = 1; return a;} else {. X = 1;. y =-1.0 * Xiang. x/Xiang. y; return a ;}/// line se advances a section from line mo_line_tui (point S, point E, double tui) {Line ret; point fa = mo_getfaxian (point (e. x-s.x, E. y-s.y); If (mo_ll (mo_xmult (E, point (s. X + FA. x, S. Y + FA. y), S), 0) {fa. X =-fa. x; fa. y =-fa. y;} double Len = SQRT (Fa. x * Fa. X + FA. y * Fa. y); Len = Len/Tui; fa. X = fa. x/Len; fa. y = fa. y/Len; S. X = S. X + FA. x, S. y = S. Y + FA. y; E. X = E. X + FA. x, E. y = E. Y + FA. y; ret. S = s; ret. E = E; return ret;} int kexing (double Jia) {int I; Yong = 0; line temp; for (I = 0; I <n; ++ I) {temp = mo_line_tui (Dian [I], Dian [(I + 1) % N], Jia); mo_hpi_addl (temp. s, temp. e);} int ret = mo_halfplaneintersect (Xian, N, Jiao); If (Ret <3) {return 0 ;}return 1 ;}int main () {int I; double banjing; while (scanf ("% d", & N), n) {Yong = 0; for (I = 0; I <n; ++ I) {scanf ("% lf", & Dian [I]. x, & Dian [I]. y);} double Shang = 5001, Xia = 0, mid; while (Xia + 1e-6 <Shang) {mid = (Shang + Xia)/2; int ret = kexing (MID); If (RET) {banjing = mid; Xia = Mid + 1e-6 ;}else {Shang = mid-1e-6 ;}} printf ("% lf \ n", banjing);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.